Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752317AbbKHVXk (ORCPT ); Sun, 8 Nov 2015 16:23:40 -0500 Received: from mail-yk0-f180.google.com ([209.85.160.180]:35953 "EHLO mail-yk0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751512AbbKHVXj convert rfc822-to-8bit (ORCPT ); Sun, 8 Nov 2015 16:23:39 -0500 MIME-Version: 1.0 In-Reply-To: <1446972440-3795-1-git-send-email-saurabh.truth@gmail.com> References: <1446972440-3795-1-git-send-email-saurabh.truth@gmail.com> Date: Sun, 8 Nov 2015 23:23:38 +0200 Message-ID: Subject: Re: [PATCH] mtd: phram: error handling From: Andy Shevchenko To: Saurabh Sengar Cc: joern@lazybastard.org, David Woodhouse , Brian Norris , "open list:MEMORY TECHNOLOGY..." , "linux-kernel@vger.kernel.org" Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2098 Lines: 64 On Sun, Nov 8, 2015 at 10:47 AM, Saurabh Sengar wrote: > registering the device with NULL pointer can lead to crash, > hence fixing it. Hmm… Why not just checking it before an register attempt? I think user is in right to know as many problems as they have at one shot, with your patch if there are two problems the user has to try twice. > > Signed-off-by: Saurabh Sengar > --- > in case of 'illegal start address' or 'illegal device length', name pointer is getting freed. > we shouldn't register the device with NULL pointer. > > drivers/mtd/devices/phram.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/drivers/mtd/devices/phram.c b/drivers/mtd/devices/phram.c > index 8b66e52..9a7aed3 100644 > --- a/drivers/mtd/devices/phram.c > +++ b/drivers/mtd/devices/phram.c > @@ -249,12 +249,14 @@ static int phram_setup(const char *val) > if (ret) { > kfree(name); > parse_err("illegal start address\n"); > + goto err; > } > > ret = parse_num64(&len, token[2]); > if (ret) { > kfree(name); > parse_err("illegal device length\n"); > + goto err; > } > > ret = register_device(name, start, len); > @@ -262,7 +264,7 @@ static int phram_setup(const char *val) > pr_info("%s device: %#llx at %#llx\n", name, len, start); > else > kfree(name); > - > +err: > return ret; > } > > -- > 1.9.1 > > -- > To unsubscribe from this list: send the line "unsubscribe linux-kernel" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > Please read the FAQ at http://www.tux.org/lkml/ -- With Best Regards, Andy Shevchenko -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/