Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp567746imu; Wed, 23 Jan 2019 01:31:18 -0800 (PST) X-Google-Smtp-Source: ALg8bN617ma4BVOMTSjmfT2iJPHkUWiudKns2TsRtvS0WVm/NzKOcbejpJr8T+dIacudAKKA/IvV X-Received: by 2002:a63:5252:: with SMTP id s18mr1327085pgl.326.1548235878358; Wed, 23 Jan 2019 01:31:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548235878; cv=none; d=google.com; s=arc-20160816; b=XzAPf918CvomkTsfW4DuII+6ONPRNxsMPFVRhth/oEUy8rtfq51WpNMA4/eral0e90 x8VozD9qjxdC/6rQUZUo/Vqaqx7o6qG9CewbK89daD9nlMq9kMFm469AbSmdWOMXWUEM e8P7a/fw+/vbtnpFJzkjv2tP9ZedCrs5Fbd9/oS4jSo9IHRoGZvDvsyeGZDkhhm+mNc8 0YgV79kB4qH+xEHOIiAK5OZa7SkN6YH/wKbzKZQEHYx1+UZZUx3BhX0f/7tdAl7Eltqh nc4NwiXdE8OjAMmhNHxRLxs3ND4Lsy+vrm4LQf0cXxZRYKZkEdYbYzPmKpgq33TjyDfo FjTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from; bh=zigK7CMWs962G3t/QLBSdjP+0YSxX0PBBY2emUJxHWs=; b=XVJ6O3fDHwaLdnoahrirzOOlWEO9xHFn1DiJG4Iou1rJe4vfKgi0EFRVntxZdjqaA9 jd4hhKHj3HQLIek+5TxcFCm2x2PCGyAU0IA4Rgdxtiw+B62asjINzHx1BDg3T0v1i1ap hwhiUiEbntD9csFt/US86FC2fjEWqdXooRpY7aOAC+b/EENgbV76jjOLHWFfqSZorXXP MNxdWTZL5BSzWSE5t88k724n4sDh9WnkrXgfBmMuNGL6N5Cb2Et+PGJ73bdfAo+8XxQQ IRnDLwxdRuw9SzeOIwO6+4RepKfV4rtOywKBaK5ka5BqOo6m0tveevXmcGQKbYum1hqR tzKg== 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 d2si17565102pfe.159.2019.01.23.01.31.03; Wed, 23 Jan 2019 01:31:18 -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 S1726954AbfAWJ2j (ORCPT + 99 others); Wed, 23 Jan 2019 04:28:39 -0500 Received: from szxga06-in.huawei.com ([45.249.212.32]:59210 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726229AbfAWJ2i (ORCPT ); Wed, 23 Jan 2019 04:28:38 -0500 Received: from DGGEMS413-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 2F511E955A46C3247450; Wed, 23 Jan 2019 17:28:37 +0800 (CST) Received: from localhost (10.177.31.96) by DGGEMS413-HUB.china.huawei.com (10.3.19.213) with Microsoft SMTP Server id 14.3.408.0; Wed, 23 Jan 2019 17:28:27 +0800 From: YueHaibing To: , , , , , CC: , , YueHaibing Subject: [PATCH v3 -next] mtd: docg3: Fix a possible memory leak of mtd->name Date: Wed, 23 Jan 2019 17:28:19 +0800 Message-ID: <20190123092819.5020-1-yuehaibing@huawei.com> X-Mailer: git-send-email 2.10.2.windows.1 MIME-Version: 1.0 Content-Type: text/plain 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 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); if (!mtd->name) return -ENOMEM; docg3->max_block = 2047; -- 2.7.0