From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753901AbcGSQCd (ORCPT ); Tue, 19 Jul 2016 12:02:33 -0400 Received: from b.ns.miles-group.at ([95.130.255.144]:44723 "EHLO radon.swed.at" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753176AbcGSQCb (ORCPT ); Tue, 19 Jul 2016 12:02:31 -0400 Subject: Re: [PATCH 1/2] mtd: nand: BUG_ON in case of no select_chip and cmd_ctrl To: Boris Brezillon References: <1468942904-26464-1-git-send-email-andrew.smirnov@gmail.com> <578E4AF0.7090507@nod.at> <20160719175912.11277116@bbrezillon> Cc: Andrey Smirnov , linux-mtd@lists.infradead.org, David Woodhouse , Brian Norris , linux-kernel@vger.kernel.org From: Richard Weinberger Message-ID: <578E4F13.1070100@nod.at> Date: Tue, 19 Jul 2016 18:02:27 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.7.1 MIME-Version: 1.0 In-Reply-To: <20160719175912.11277116@bbrezillon> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Am 19.07.2016 um 17:59 schrieb Boris Brezillon: > On Tue, 19 Jul 2016 17:44:48 +0200 > Richard Weinberger wrote: > >> Am 19.07.2016 um 17:41 schrieb Andrey Smirnov: >>> If no user specified chip->select_chip() function is provided, code in >>> nand_base.c will automatically set this hook to nand_select_chip(), >>> which in turn depends on chip->cmd_ctrl() hook being valid. Not >>> providing both of those functions in NAND controller driver (for example >>> by mistake) will result in a bit cryptic segfault. Replace it with >>> explicit BUG_ON statement so it would be obvious what went wrong. >>> >>> Signed-off-by: Andrey Smirnov >>> --- >>> drivers/mtd/nand/nand_base.c | 4 +++- >>> 1 file changed, 3 insertions(+), 1 deletion(-) >>> >>> diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c >>> index ce7b2ca..57043a6 100644 >>> --- a/drivers/mtd/nand/nand_base.c >>> +++ b/drivers/mtd/nand/nand_base.c >>> @@ -3128,8 +3128,10 @@ static void nand_set_defaults(struct nand_chip *chip, int busw) >>> if (chip->waitfunc == NULL) >>> chip->waitfunc = nand_wait; >>> >>> - if (!chip->select_chip) >>> + if (!chip->select_chip) { >>> + BUG_ON(!chip->cmd_ctrl); >> >> Please don't add new BUG_ON() calls. WARN_ON() is good enough to raise the driver developer's >> attention and won't kill the machine. > > Not sure a BUG_ON() is worst than a NULL-pointer exception ;-). When this really just triggers a NULL-pointer exception, we don't need a BUG_ON or WARN_ON at all since the kernel can tell anyway what went wrong. >>From the patch description I thought it is a more cryptic problem... Thanks, //richard