Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2666575imu; Thu, 24 Jan 2019 17:42:02 -0800 (PST) X-Google-Smtp-Source: ALg8bN7RboubTnPayK2LphC4d8GUZ71Y144d012y66j3Qwx4ArHk9JTUX8H2lna5FhooNYeU+4bL X-Received: by 2002:a62:5884:: with SMTP id m126mr8876514pfb.177.1548380522190; Thu, 24 Jan 2019 17:42:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548380522; cv=none; d=google.com; s=arc-20160816; b=JIQ7UHQv2eaD2MuPmYyWVsPU5Ofwi2W6o1UA6/7/fUEx4uRIbSOWAGU6xfpDM0bDOD 4sTCqMbWxYuAEjjiCUdASsLl1wwwfGRnCQCQq+wN8bgTk5IJV5wZBV6s5muJ6bhbS2/Q 7roZgP328pIxt3vAKtX9YHwmrXQvBYLt5Fk2UTEZcrqIynop4AFveFSaYSCqdnXGtMNc 1GyeESyLy2wtFRXHIuZxZU0YxgXngGVzv0OJH2+Ku0kFrqR0uDH6RBCCgzDh0ITnPVUf 0C194wNcESmXVDdUNSYYbq3Vfaae8ipiHOgg9hlMxxQfUGx1kYw1O7zoLdqelgtHYXPC ShPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:cc:references:to :subject; bh=mhCOpfYsd2lIc19x6uGgPEgP+2l0hvmnTl8DHwjFIgc=; b=hPvd7j+Ow7vVPBBDurHgqywPyBMfag9REPZGGq92XqvENt8cFGn+IMQUhyZH01QVaK 3DbMpMhro0KdJHNnrt1RcCnO9gO989luxlFXPYl7lA5uoHLd+drm635BiRyr5YBiNlXd JZ+mFFtyA48xXZnYF7NBn8WkEEiw0Mpw6fB3cCewpkGOkcua7iCklUKlFD0qmMuRzcKt GafX1154pV26VMGNhSzjN20lcODfJhtO5iMfxduvZf+40RFtvM7+5ChFMgSHkNATw99m YrrbtnmRY2tuZMaqC6KtYheVcI3fqLsPlyN7o3b/XMgj/Yh1gXrcTIFzrEVp0QE6DrSG 5jbA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a20si23597227pfh.163.2019.01.24.17.41.46; Thu, 24 Jan 2019 17:42:02 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728449AbfAYBkn (ORCPT + 99 others); Thu, 24 Jan 2019 20:40:43 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:2747 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727983AbfAYBkn (ORCPT ); Thu, 24 Jan 2019 20:40:43 -0500 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 27B51122F7A6A8AEA996; Fri, 25 Jan 2019 09:40:41 +0800 (CST) Received: from [127.0.0.1] (10.177.31.96) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.408.0; Fri, 25 Jan 2019 09:40:38 +0800 Subject: Re: [PATCH v3 -next] mtd: docg3: Fix a possible memory leak of mtd->name To: Boris Brezillon References: <20190123092819.5020-1-yuehaibing@huawei.com> <20190124160047.6091b3e3@bbrezillon> CC: , , , , , , From: YueHaibing Message-ID: Date: Fri, 25 Jan 2019 09:40:34 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 In-Reply-To: <20190124160047.6091b3e3@bbrezillon> Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.177.31.96] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2019/1/24 23:00, Boris Brezillon wrote: > On Wed, 23 Jan 2019 17:28:19 +0800 > YueHaibing wrote: > >> In case DOC_CHIPID_G3, mtd->name is not freed in err handling path, >> which is alloced by kasprintf(). Fix this by using devm_kasprintf(). >> >> Fixes: ae9d4934b2d7 ("mtd: docg3: add multiple floor support") >> Signed-off-by: YueHaibing >> --- >> v3: use devm_kasprintf >> --- >> drivers/mtd/devices/docg3.c | 4 ++-- >> 1 file changed, 2 insertions(+), 2 deletions(-) >> >> diff --git a/drivers/mtd/devices/docg3.c b/drivers/mtd/devices/docg3.c >> index 4c94fc0..59ca4f5 100644 >> --- a/drivers/mtd/devices/docg3.c >> +++ b/drivers/mtd/devices/docg3.c >> @@ -1767,8 +1767,8 @@ static int __init doc_set_driver_info(int chip_id, struct mtd_info *mtd) >> >> switch (chip_id) { >> case DOC_CHIPID_G3: >> - mtd->name = kasprintf(GFP_KERNEL, "docg3.%d", >> - docg3->device_id); >> + mtd->name = devm_kasprintf(docg3->dev, GFP_KERNEL, "docg3.%d", >> + docg3->device_id); > > You forgot to remove the kfree() in the ->remove() path. Oops..., I will fix this. Thanks a lot! > >> if (!mtd->name) >> return -ENOMEM; >> docg3->max_block = 2047; > > > . >