From patchwork Thu Jul 21 21:59:20 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 651466 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2001:1868:205::9]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3rwSRx2ZhVz9t0q for ; Fri, 22 Jul 2016 08:02:05 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=ZLf9950x; dkim-atps=neutral Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bQM0s-0001VO-UJ; Thu, 21 Jul 2016 22:00:14 +0000 Received: from mail-pf0-x242.google.com ([2607:f8b0:400e:c00::242]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bQM0n-0000Gj-HI for linux-mtd@lists.infradead.org; Thu, 21 Jul 2016 22:00:10 +0000 Received: by mail-pf0-x242.google.com with SMTP id g202so6100920pfb.1 for ; Thu, 21 Jul 2016 14:59:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=4HGH+M4XqskucB83ASyV56s7hnFbfgv7NgBmTKGLgkY=; b=ZLf9950x2iDSYU+DAXlL24YP7Fr2W7hXYUgPVxmy/9mL/yNBFxUI1bJLN2tnqAbR1w FlNYKvLCdI5BXnT9xHWZtTfldzvVhIMT82ijir4fWO1Vpp5QOYxV3gJstclpO09VDoBw +kjZ0PA+7b3+7zN7g8OpXwuEZLr2lVNGY9ynyFchvWzqyabvXgjK3EiBAPd/bSiYM6hb Io6DVfM/RlWx9uMWaLXvX5v+IHrNFCOmjFAvpwq9BHxaItFnEANVp25Hzz5zLbydiz6p 6s1oK5blCt81Ks0l9bl7LKsia07bYI8gN1QJLuyOQGn6xGg4txGYwu4T/m3+lCjIz9dZ K4BQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=4HGH+M4XqskucB83ASyV56s7hnFbfgv7NgBmTKGLgkY=; b=TUC8Unjf8tIg1E9qH5pa9npS9Ue8KcZPYmlXwH8ihK61jBq76W6y++QxsbB+GJvB4R Zu9rEfWDdvvj3ynVPWWqDbLUL+YznL2DJHPHsfNB9CXkm2uHaPi5ZB0qfZsFFtdpXRZk +ST+uxXOQIo2vUV15dx+JzIRVJMste+xfpLQ+4GbQeBe8oRrqjiK1z7oquilZ62i4BTN K5wt9A1kWIGQ5yFtASGZCAMfgKm9EViSMlIFmh3OxCjKX4yizL3Ap9JyD3To4QPAZ9Vp VLS1QeeT8fUx+RdcTqx663WBq9dfKi0+dQ0AqzX4zDSsCoQiLIzjFYD57CLHOTUmbPSQ e6MA== X-Gm-Message-State: AEkoousevF828cesrsayPw6evaHOcJ4Dq8KOzKssl6NQxPQknsMQhvWmnOqnK9VMWSAeNg== X-Received: by 10.98.16.75 with SMTP id y72mr758135pfi.50.1469138390875; Thu, 21 Jul 2016 14:59:50 -0700 (PDT) Received: from squirtle.localdomain.com ([173.226.206.194]) by smtp.gmail.com with ESMTPSA id xs12sm14574609pac.7.2016.07.21.14.59.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 21 Jul 2016 14:59:50 -0700 (PDT) From: Andrey Smirnov To: linux-mtd@lists.infradead.org Subject: [PATCH v3 1/2] mtd: nand: Error out if cmd_ctrl() is missing Date: Thu, 21 Jul 2016 14:59:20 -0700 Message-Id: <1469138361-14173-3-git-send-email-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1469138361-14173-1-git-send-email-andrew.smirnov@gmail.com> References: <1469138361-14173-1-git-send-email-andrew.smirnov@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160721_150009_678759_B741628E X-CRM114-Status: GOOD ( 13.34 ) X-Spam-Score: -2.7 (--) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-2.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [2607:f8b0:400e:c00:0:0:0:242 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (andrew.smirnov[at]gmail.com) -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Boris Brezillon , Andrey Smirnov , Richard Weinberger , linux-kernel@vger.kernel.org, Brian Norris , David Woodhouse MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.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. Same is true for chip->cmdfunc(). To avoid the above scenario add a check in nand_scan_dent and error out if cmd_ctrl() is not provided. Suggested-by: Boris Brezillon Suggested-by: Brian Norris Signed-off-by: Andrey Smirnov --- Changes since v2: - Check moved to nand_scan_ident drivers/mtd/nand/nand_base.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c index ce7b2ca..93f5432 100644 --- a/drivers/mtd/nand/nand_base.c +++ b/drivers/mtd/nand/nand_base.c @@ -3997,6 +3997,15 @@ int nand_scan_ident(struct mtd_info *mtd, int maxchips, if (!mtd->name && mtd->dev.parent) mtd->name = dev_name(mtd->dev.parent); + if ((!chip->cmdfunc || !chip->select_chip) && !chip->cmd_ctrl) { + /* + * Default functions assigned for chip_select() and + * cmdfunc() both expect cmd_ctrl() to be populated, + * so we need to check that that's the case + */ + pr_err("chip.cmd_ctrl() callback is not provided"); + return -EINVAL; + } /* Set the default functions */ nand_set_defaults(chip, chip->options & NAND_BUSWIDTH_16);