Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4762367pxj; Tue, 25 May 2021 16:10:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyjOfsv8O8lIq7L74oBepYK1iD4qSW+uyEVqbkEYTvtUG6V2fCod0hBpwPz8y9DxR9mt0Jl X-Received: by 2002:a02:970c:: with SMTP id x12mr33180195jai.21.1621984230815; Tue, 25 May 2021 16:10:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621984230; cv=none; d=google.com; s=arc-20160816; b=Lz0qp8KIn4fw3HMWwNdN37X4n3ItqUc/McjPxP31kTKK3t6srv0IFN8nOZXVwFG77c n6v2ZLoRNZERDvINA0DRkajU5qfHAxcefJUmjXLBjzOG+Zp5/3y+FshIoLfGZ028zFSm LLL4vNNLsrOroSxYoy8//PGXnCiI8ghv/jSDwJeUiBAN0PzWADuRPRzpeKluRis5JmW2 WIWFh6puf0W97w8hEoQ89karxvQExOY3amGVLkyDT5hiDJ8piIuMDPMbfchkD736X0IV MPiNSDshMa0BN7NwcHPYpp8mDJo2sIs10liYPuEvMym8mCfK0fzr2kEyCxeFas0X1Jk0 B2ng== 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=X1MvS/6mSvBdfpSbPfN/7JJWpwiBa9tcmoBU0a7X3Cs=; b=OpV1TvVoFDS34yEfaQ6LCj3LjboaOCC4B+gnxb2YOh0o1CIQGso1c3qChxBKTUAxPR VyOdm4ermiWIva5nUOkB8heHkqOzKQGKJ5GPkne0BY68pBWC1iqPOFsT6yVXKBZ5zHDw RR9vUvEaUhe8BDbVqkrdfqhfh6pEGp2oOZFKAimhbWn3BKaWVO4uIqH3NlJp/JTvdq1C rpeyi39pO5iXb/pYWyUjDDU4SbvAItT0fZsL5BWjUKbqxWIc4wBjfGoKnwy37d7AjIiP HY4r4tQ2rsAo5vatUO0mcGc5rrDVO/BQSHGriE8sDhtUkirPaMKaurJmNec+x0oLwato 3KeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=JbhzrHYW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z22si19023038iof.57.2021.05.25.16.10.17; Tue, 25 May 2021 16:10:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=JbhzrHYW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230202AbhEYXLO (ORCPT + 99 others); Tue, 25 May 2021 19:11:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52182 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229610AbhEYXLN (ORCPT ); Tue, 25 May 2021 19:11:13 -0400 Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [IPv6:2a00:1450:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B5F18C061574; Tue, 25 May 2021 16:09:41 -0700 (PDT) Received: by mail-ed1-x52b.google.com with SMTP id g7so26042789edm.4; Tue, 25 May 2021 16:09:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=X1MvS/6mSvBdfpSbPfN/7JJWpwiBa9tcmoBU0a7X3Cs=; b=JbhzrHYWbaZWQbBevPTwVRlDDqmSjaoc6umPdR/hxegRe9Wus8j9yoSRWUje/zaqLq 3umESW2EMLgRPhGH7uyEKu2uAog1EajMO+ic8Zg1ZsQ1eTm7ufI+810GUOC4FiDMzwDf /dtNNsK8zDDjTHEqOJQrtVH0lq/PSXzRu7cTi16xjya4EGHj1zXxjooZzwYE/nYGSI97 KDXn+XksNlQMSB9ppfUuCHnNQPjpX/TI/hrvwh0BalEqePmhY69Y4nMqktargP1hzacm rwrlv74ASPp1xk1f9gIz3V9/+keZs1a7QuRpmrMG/1uwuFdwH8TGo4RyrMkHPkNHU5wa Eq/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=X1MvS/6mSvBdfpSbPfN/7JJWpwiBa9tcmoBU0a7X3Cs=; b=Aqq60taKiGVNGydMZslolL6QU6+k5FV3hMSUERclHOvvdLzWpKh/uEOW0vCo3bt1me L1emFAucBJAb8bH542O9o32c1A45TRZZDAWlOu5Ya7GBhFl29EEb9ScdSjYR00/Ng9fZ IQRGrSKwBqBt1lccOfnUgZ+21ja8tLNy9G4S8qBlMEkS+IbtmAN+2Nky3Mk1gwgOUREa aK9ofmh9at2i11T0vtWVcmGf1L/h7TvFrxnT+r5wDFZiPRlh/BBrc61mBn8DJBVsyvKU D4WHeIq3jm5sTVUiY5Gi61IjHhw6cClwv9R90mLhQSRY76XfGyBoDI2m3/rwwDBs2Pt0 mIpg== X-Gm-Message-State: AOAM5315eMEWxCHv56Q67OXD2ajLSzj4fEoMcp4jysVDnTBP7cQ6WUHK V9l5mQ9wtL6PKKkeAJY+sjnUVYygRoBnoA== X-Received: by 2002:a05:6402:2706:: with SMTP id y6mr6247878edd.355.1621984179869; Tue, 25 May 2021 16:09:39 -0700 (PDT) Received: from Ansuel-xps.localdomain (93-35-189-2.ip56.fastwebnet.it. [93.35.189.2]) by smtp.googlemail.com with ESMTPSA id zg18sm9503105ejb.41.2021.05.25.16.09.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 May 2021 16:09:39 -0700 (PDT) From: Ansuel Smith To: Andy Gross , Bjorn Andersson , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Manivannan Sadhasivam , linux-arm-msm@vger.kernel.org, linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Ansuel Smith Subject: [PATCH v2] mtd: parsers: qcom: Fix leaking of partition name Date: Wed, 26 May 2021 01:09:31 +0200 Message-Id: <20210525230931.30013-1-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add cleanup function as the name variable for the partition name was allocaed but never freed after the use as the add mtd function duplicate the name and free the pparts struct as the partition name is assumed to be static. The leak was found using kmemleak. Fixes: 803eb124e1a6 ("mtd: parsers: Add Qcom SMEM parser") Signed-off-by: Ansuel Smith --- drivers/mtd/parsers/qcomsmempart.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/mtd/parsers/qcomsmempart.c b/drivers/mtd/parsers/qcomsmempart.c index d9083308f6ba..06a818cd2433 100644 --- a/drivers/mtd/parsers/qcomsmempart.c +++ b/drivers/mtd/parsers/qcomsmempart.c @@ -159,6 +159,15 @@ static int parse_qcomsmem_part(struct mtd_info *mtd, return ret; } +static void parse_qcomsmem_cleanup(const struct mtd_partition *pparts, + int nr_parts) +{ + int i; + + for (i = 0; i < nr_parts; i++) + kfree(pparts[i].name); +} + static const struct of_device_id qcomsmem_of_match_table[] = { { .compatible = "qcom,smem-part" }, {}, @@ -167,6 +176,7 @@ MODULE_DEVICE_TABLE(of, qcomsmem_of_match_table); static struct mtd_part_parser mtd_parser_qcomsmem = { .parse_fn = parse_qcomsmem_part, + .cleanup = parse_qcomsmem_cleanup, .name = "qcomsmem", .of_match_table = qcomsmem_of_match_table, }; -- 2.31.1