From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753647AbcGSPmM (ORCPT ); Tue, 19 Jul 2016 11:42:12 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:32924 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751575AbcGSPmK (ORCPT ); Tue, 19 Jul 2016 11:42:10 -0400 From: Andrey Smirnov To: linux-mtd@lists.infradead.org Cc: Andrey Smirnov , Boris Brezillon , Richard Weinberger , David Woodhouse , Brian Norris , linux-kernel@vger.kernel.org Subject: [PATCH 1/2] mtd: nand: BUG_ON in case of no select_chip and cmd_ctrl Date: Tue, 19 Jul 2016 08:41:43 -0700 Message-Id: <1468942904-26464-1-git-send-email-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.5.5 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); chip->select_chip = nand_select_chip; + } /* set for ONFI nand */ if (!chip->onfi_set_features) -- 2.5.5