Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp2512401rdb; Fri, 22 Sep 2023 00:09:38 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGElnzrP+ilLLRHC4pLhrI4nhPdI7qzOlb9aExUqxWN1Io0jGYvWyNKzpfqSZvKOGzxZ8Mp X-Received: by 2002:a05:6358:c1c:b0:134:c859:d32a with SMTP id f28-20020a0563580c1c00b00134c859d32amr9772629rwj.25.1695366578005; Fri, 22 Sep 2023 00:09:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695366577; cv=none; d=google.com; s=arc-20160816; b=zlxJCP4Ab5ButqzyzR19215wJOAq5LJMIvfpRu0BMR0MwlPlz+3SJY+i6+S+XR0nPp QVsGypLs3GfAb0DLFDnae3aFte4UAMke1/h7JtipcjE6eWsQm5/J7Wg4M9qgFChSqABL J2+fnIeVDy3POhHh8u398LxQikspkutGGGyVulij4/iRPWVFdfY4B7eUfr8vrnfuinV/ LTZvr4jn8JoB9vpTjnojxPx73Uje9dE0HcNltyKMr9uUdYT0xkhZY7x694M2xh+cIqok ol1anFt2k+4uIgJqwywXfEEzXEyWJhmKDPUDIP89HAgplaqCy1TIkZJSvuC/dO06tIDR LdfQ== 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=CNIjKqWBYJRXMJgT7L7SM8zG22UEzfPx+zde9DnsbOI=; fh=4dwsj0wOHwoGJ87tjTHH9cQPnwAQlbshPyVESApVhsc=; b=i1ik0ZWo852RF4k/484Owt3VO9Mstkhu83pzKR8OCgAQWBgLVaXTTCMSA8xLJ22UkV ukjX2OS+AgSlmAWoJNIoY2/V7l53YhhMMVNJ/kg08xcIoyZZ4yOV4z+6FDn06DB4tNQm edSrfpsv8BHIbWebOCRH3eSpnagOJOewIt243tz5KkEKZtp/Lg5Fc9EosD4gnGtDziTb 3/yT+/dP3OZFAnDy6UjYieItNjM37DpRaLCxT1MNsLHCAMd5ItDLDS1jIjFA8qvq7a9O BwXQvVUZmKE4rDEUPPZqBTmTYKOECxFWXz3nW5pAS2xAdQfaCija+UvecQwkEe0B1eU3 0kcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=P3OD9Gfq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id e2-20020a656882000000b00578c914490asi3187165pgt.427.2023.09.22.00.09.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 00:09:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=P3OD9Gfq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id F09CC84D1200; Thu, 21 Sep 2023 19:52:54 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230246AbjIVCwz (ORCPT + 99 others); Thu, 21 Sep 2023 22:52:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229497AbjIVCwy (ORCPT ); Thu, 21 Sep 2023 22:52:54 -0400 Received: from m15.mail.163.com (m15.mail.163.com [45.254.50.219]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 85C8B192 for ; Thu, 21 Sep 2023 19:52:47 -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=CNIjK qWBYJRXMJgT7L7SM8zG22UEzfPx+zde9DnsbOI=; b=P3OD9GfqgQpqnkjdxgyCF XZW69zBrwX20z8puFpc8xII0vUPke0ph8AI3nvbnV8yCCkBUwnNaAXP0M1+PunIa rdwKU3iM0h/y8ERfIz+UyOhlRTtLxMIvbmLcjUabCrNKrr8K7nlQeJUYQC3K2KxY AMaZ1pgTmx1Mks4j/qhs6U= Received: from icess-ProLiant-DL380-Gen10.. (unknown [183.174.60.14]) by zwqz-smtp-mta-g2-1 (Coremail) with SMTP id _____wCXlmJkAQ1lBhMMCw--.10183S4; Fri, 22 Sep 2023 10:52:32 +0800 (CST) From: Ma Ke To: mchehab+huawei@kernel.org, sboyd@kernel.org Cc: linux-kernel@vger.kernel.org, Ma Ke Subject: [PATCH] spmi: hisi-spmi-controller: fix potential memory leak in spmi_controller_probe() Date: Fri, 22 Sep 2023 10:52:16 +0800 Message-Id: <20230922025216.3604978-1-make_ruc2021@163.com> X-Mailer: git-send-email 2.37.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: _____wCXlmJkAQ1lBhMMCw--.10183S4 X-Coremail-Antispam: 1Uf129KBjvdXoW7Wr1rCw47ZFyDGw13Xr13urg_yoWkKwc_Cr 48GFW7ur1kCrW2kwn5tr4rJF9Yva48Xw10k3W0qw17Ja9Yv3Z0qry7XrWDZrW8JFs8Ar13 Gr1jvF48A3W8AjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7xRthFxDUUUUU== X-Originating-IP: [183.174.60.14] X-CM-SenderInfo: 5pdnvshuxfjiisr6il2tof0z/1tbivgvyC1Zci0HukAABsz X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Thu, 21 Sep 2023 19:52:55 -0700 (PDT) spmi_controller_alloc() allocates a memory space for ctrl. When some errors occur, ctrl should be handled by spmi_controller_put() and set spmi_controller->controller = NULL because spmi_controller->controller has a dangling pointer to the freed memory. When the failure happens, the function returns without calling spmi_controller_put() and setting spmi_controller->controller = NULL, which will lead to a memory leak. When the failure happens, we can fix it by calling spmi_controller_put() and setting spmi_controller->controller = NULL in all of the places where we call spmi_controller_put(). Signed-off-by: Ma Ke --- drivers/spmi/hisi-spmi-controller.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/spmi/hisi-spmi-controller.c b/drivers/spmi/hisi-spmi-controller.c index 9cbd473487cb..5b3cfa7f5056 100644 --- a/drivers/spmi/hisi-spmi-controller.c +++ b/drivers/spmi/hisi-spmi-controller.c @@ -321,6 +321,7 @@ static int spmi_controller_probe(struct platform_device *pdev) err_put_controller: spmi_controller_put(ctrl); + spmi_controller->controller = NULL; return ret; } -- 2.37.2