Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp120464imw; Mon, 4 Jul 2022 06:20:34 -0700 (PDT) X-Google-Smtp-Source: AGRyM1s7WEAARLMaQjK8m3FxRjstSTbHif+TMSH/ivhR9sphaRXNXNY1jYauVLzrQqfbwCTmBwP/ X-Received: by 2002:a17:902:7792:b0:16a:463e:296c with SMTP id o18-20020a170902779200b0016a463e296cmr38047157pll.138.1656940834009; Mon, 04 Jul 2022 06:20:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656940834; cv=none; d=google.com; s=arc-20160816; b=HJINhIG8RixvuubgTdYZIlLFCO8TaI1BAg0VBWO3x8H+FFFEApVrLhHmm1ZpDnMPBn hKiqmQrEGcQ9L7fxrosnZx4iAEB6IuBTjr9B8mHNyEWZSlxAcvSWZBB3b3Q37q5J+VEj J+q8OdciLluT0mAKCeG4VCmSE59ZkLATbILzC2bTQEv3ZsPs1h9a3dMAsRtDNnhbf4z+ +YxReIRupUiOZ6TMp6OtXHmP6PRI1pODvcQkrEFa+Rb6aC3w+k12nVQCHervvDdaSyro 9FCb0vBKTEInCCydcUIIIcRN0eT5pMgj89OAIrnIHI9BhmM+W47kF0OWOH5Q2kn4F6ri 8wXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=w39Pq2DmWEWjcTsIwK+1m9Pu/MO56ER0XvIIEHXf8Mw=; b=0gdv+g2iHENlMlWaqgcPhswP+WWe8f6fxmwnmrkIbjW7BpaydyIaPPCDnkuSq+OUO5 o58DgJvOfAU6n5VSnZjSTG07q8YgHORTXXzDGYXCReQuMj5W4Ss5MwGeCHv7K5BlEq3i gRl0cCDtuK8jq+1gXXlHT9PreOTudri+nrzzUhIa4fHD/2GBzn92YEK/Dq0sGhHYAEmX oJjd1xTYcnNlFR5Ex9ytfPWloVivHt7WsFqHkUirScAhmSnhJB4Bt5O5Tc/lcRqPDvJH Z298lQCmp6ybYXVyjEgWu3ojAM1+JRKmem3zMGK/dEzeIDtdgGSGn9otP20m9ZpBmPYM E8hA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=iaiPsIjM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e6-20020a17090301c600b0016bdbd7be95si6180305plh.514.2022.07.04.06.20.12; Mon, 04 Jul 2022 06:20:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=iaiPsIjM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234529AbiGDNAF (ORCPT + 99 others); Mon, 4 Jul 2022 09:00:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234453AbiGDNAD (ORCPT ); Mon, 4 Jul 2022 09:00:03 -0400 Received: from mail-m975.mail.163.com (mail-m975.mail.163.com [123.126.97.5]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 723796462 for ; Mon, 4 Jul 2022 06:00:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=w39Pq 2DmWEWjcTsIwK+1m9Pu/MO56ER0XvIIEHXf8Mw=; b=iaiPsIjMbNoM9IHCL+5jI 7JXNnFCodiHjvHqePjlofT09r1JVAq38UpGKVyTDncADo99LNR2MRiJMxzgdyBcg jsjlSdx5zoPinyKrG087j39HrElnBdlpWmk4yhFyRQHIvSweKz0VLAUHkJahcNPW DIt0oK8txCPPAqTU0gB8iU= Received: from localhost.localdomain (unknown [123.112.69.106]) by smtp5 (Coremail) with SMTP id HdxpCgCHlTAr5MJiBdGUMQ--.44107S4; Mon, 04 Jul 2022 20:59:34 +0800 (CST) From: Jianglei Nie To: iwona.winiarska@intel.com Cc: openbmc@lists.ozlabs.org, linux-kernel@vger.kernel.org, Jianglei Nie Subject: [PATCH] peci: fix potential memory leak in devm_adev_add() Date: Mon, 4 Jul 2022 20:59:22 +0800 Message-Id: <20220704125922.2240585-1-niejianglei2021@163.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: HdxpCgCHlTAr5MJiBdGUMQ--.44107S4 X-Coremail-Antispam: 1Uf129KBjvdXoWruFyDKF1xGFW8try3KFykZrb_yoWfCrb_uF 1a9rZ5Xr1DGanxtw43J3yrZrySyF10q3yxZF4SyFyfAay5Xa17uayqqrZxJ345Ww47uFZ8 Zr9rtryUJwn3GjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7xR_L0etUUUUU== X-Originating-IP: [123.112.69.106] X-CM-SenderInfo: xqlhyxxdqjzvrlsqjii6rwjhhfrp/1tbiQxY0jFc7acgiiwAAsJ X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org devm_adev_add() allocates a memory chunk for "adev" and "adev->name" with adev_alloc(). When auxiliary_device_add() fails, the function calls auxiliary_device_uninit(), which doesn't release the allocated "adev" and "adev->name", thus leading to a memory leak bug. We should call adev_release() instead of auxiliary_device_uninit() to release the "adev" and "adev->name". Signed-off-by: Jianglei Nie --- drivers/peci/cpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/peci/cpu.c b/drivers/peci/cpu.c index 68eb61c65d34..de865997ccde 100644 --- a/drivers/peci/cpu.c +++ b/drivers/peci/cpu.c @@ -248,7 +248,7 @@ static int devm_adev_add(struct device *dev, int idx) ret = auxiliary_device_add(adev); if (ret) { - auxiliary_device_uninit(adev); + adev_release(&adev->dev); return ret; } -- 2.25.1