From patchwork Wed Apr 3 14:46:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geert Uytterhoeven X-Patchwork-Id: 10883977 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1BB12922 for ; Wed, 3 Apr 2019 14:47:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 05648288C3 for ; Wed, 3 Apr 2019 14:47:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EDB0A2891A; Wed, 3 Apr 2019 14:47:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A3F46288C3 for ; Wed, 3 Apr 2019 14:47:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726218AbfDCOrA (ORCPT ); Wed, 3 Apr 2019 10:47:00 -0400 Received: from xavier.telenet-ops.be ([195.130.132.52]:37418 "EHLO xavier.telenet-ops.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726168AbfDCOrA (ORCPT ); Wed, 3 Apr 2019 10:47:00 -0400 Received: from ramsan ([84.194.111.163]) by xavier.telenet-ops.be with bizsmtp id vqmy1z00K3XaVaC01qmyXq; Wed, 03 Apr 2019 16:46:58 +0200 Received: from rox.of.borg ([192.168.97.57]) by ramsan with esmtp (Exim 4.90_1) (envelope-from ) id 1hBhAI-0003ah-Aj; Wed, 03 Apr 2019 16:46:58 +0200 Received: from geert by rox.of.borg with local (Exim 4.90_1) (envelope-from ) id 1hBhAI-00029w-9J; Wed, 03 Apr 2019 16:46:58 +0200 From: Geert Uytterhoeven To: Mark Brown Cc: Linus Walleij , linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH] spi: Add missing error handling for CS GPIOs Date: Wed, 3 Apr 2019 16:46:56 +0200 Message-Id: <20190403144656.8257-1-geert+renesas@glider.be> X-Mailer: git-send-email 2.17.1 Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP While devm_gpiod_get_index_optional() returns NULL if the GPIO is not present (i.e. -ENOENT), it may still return other error codes, like -EPROBE_DEFER. Currently these are not handled, leading to unrecoverable failures later in case of probe deferral: gpiod_set_consumer_name: invalid GPIO (errorpointer) gpiod_direction_output: invalid GPIO (errorpointer) gpiod_set_value_cansleep: invalid GPIO (errorpointer) gpiod_set_value_cansleep: invalid GPIO (errorpointer) gpiod_set_value_cansleep: invalid GPIO (errorpointer) Detect and propagate errors to fix this. Fixes: f3186dd876697e69 ("spi: Optionally use GPIO descriptors for CS GPIOs") Signed-off-by: Geert Uytterhoeven Reviewed-by: Linus Walleij --- drivers/spi/spi.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index bd2a424672df266c..2ad20c735b61c4aa 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -2199,6 +2199,8 @@ static int spi_get_gpio_descs(struct spi_controller *ctlr) */ cs[i] = devm_gpiod_get_index_optional(dev, "cs", i, GPIOD_OUT_LOW); + if (IS_ERR(cs[i])) + return PTR_ERR(cs[i]); if (cs[i]) { /*