From patchwork Mon May 30 14:59:01 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 68846 Delivered-To: patch@linaro.org Received: by 10.140.92.199 with SMTP id b65csp1449817qge; Mon, 30 May 2016 07:59:14 -0700 (PDT) X-Received: by 10.66.139.108 with SMTP id qx12mr6408112pab.27.1464620354313; Mon, 30 May 2016 07:59:14 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d2si36978128pfb.152.2016.05.30.07.59.14; Mon, 30 May 2016 07:59:14 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-gpio-owner@vger.kernel.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754969AbcE3O7N (ORCPT + 4 others); Mon, 30 May 2016 10:59:13 -0400 Received: from mail-lf0-f54.google.com ([209.85.215.54]:35219 "EHLO mail-lf0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754704AbcE3O7M (ORCPT ); Mon, 30 May 2016 10:59:12 -0400 Received: by mail-lf0-f54.google.com with SMTP id w16so61531772lfd.2 for ; Mon, 30 May 2016 07:59:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=cI0Y+zMt9wo0OzdhrfHUXJEftncXNC84sij+WQmFK1o=; b=AjSXTICnLzychWWydSE9NaMXOlxGtSGyENb6okygPZGcHp4Z9fLjHWM9qk55Tpa3zJ UZIP0cWakVJSTuCEWAJp6Xmyq6tOpD5BjNWwlxA7m3InHGhnXgR4MG7sJgOOvBfq0I5m KdSJPjppgUDgWN+vmsjJDD8ZwKQP0JC910KzA= 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:mime-version :content-transfer-encoding; bh=cI0Y+zMt9wo0OzdhrfHUXJEftncXNC84sij+WQmFK1o=; b=TfttMMEElc7uZqR9IPd2HtGaOKyogc7z2hHBuhF+d4f//OH+jBowkiLj59sEEO5WIm CkizGCn4TwPk9XPaETiUNBhfi3Q/+78Tj0k0E+aE+HVyPTT/YVp68UhwGQ/OoaMO6neL E7T+bZ6TBwQ+UhLunCrh2AN3LGKKN0pJwpIZCTZESeNGkXtP1PJPx2ZW/REhNGdATscp rwK+6SixBu3zSlDoq4fvMOxwkb+zQacLSy2jScZhwqfEz78O3fA/plkPWugRaqvLuEsR ICXedDesANwmQchWdTdrBHCUfMHPzYcfUVhOCQFfpg1Lq9SR7bXQ28p9N9kf290uIXmq B2Cw== X-Gm-Message-State: ALyK8tJLLWagChSMpTY7/ZLQjBKf48PIv5vyiEAJucKiZwIBvg75rpHVvIFx5wjMALRG+a2a X-Received: by 10.25.159.194 with SMTP id i185mr7783483lfe.130.1464620351248; Mon, 30 May 2016 07:59:11 -0700 (PDT) Received: from localhost.localdomain ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id po2sm4444309lbb.49.2016.05.30.07.59.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 30 May 2016 07:59:09 -0700 (PDT) From: Linus Walleij To: linux-gpio@vger.kernel.org, Alexandre Courbot Cc: Linus Walleij , stable@vger.kernel.org, Sergei Shtylyov , Florian Fainelli , Andrew Lunn Subject: [PATCH] gpio: bail out silently on NULL descriptors Date: Mon, 30 May 2016 16:59:01 +0200 Message-Id: <1464620341-24326-1-git-send-email-linus.walleij@linaro.org> X-Mailer: git-send-email 2.4.11 MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org In fdeb8e1547cb9dd39d5d7223b33f3565cf86c28e ("gpio: reflect base and ngpio into gpio_device") assumed that GPIO descriptors are either valid or error pointers, but gpiod_get_[index_]optional() actually return NULL descriptors and then all subsequent calls should just bail out. Cc: stable@vger.kernel.org Cc: Sergei Shtylyov Cc: Florian Fainelli Cc: Andrew Lunn Fixes: fdeb8e1547cb ("gpio: reflect base and ngpio into gpio_device") Reported-by: Uwe Kleine-König Signed-off-by: Linus Walleij --- drivers/gpio/gpiolib.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) -- 2.4.11 -- To unsubscribe from this list: send the line "unsubscribe linux-gpio" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 68dbff5d8f57..246b6b051b0d 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -1367,10 +1367,13 @@ done: /* * This descriptor validation needs to be inserted verbatim into each * function taking a descriptor, so we need to use a preprocessor - * macro to avoid endless duplication. + * macro to avoid endless duplication. If the desc is NULL it is an + * optional GPIO and calls should just bail out. */ #define VALIDATE_DESC(desc) do { \ - if (!desc || !desc->gdev) { \ + if (!desc) \ + return 0; \ + if (!desc->gdev) { \ pr_warn("%s: invalid GPIO\n", __func__); \ return -EINVAL; \ } \ @@ -1381,7 +1384,9 @@ done: } } while (0) #define VALIDATE_DESC_VOID(desc) do { \ - if (!desc || !desc->gdev) { \ + if (!desc) \ + return; \ + if (!desc->gdev) { \ pr_warn("%s: invalid GPIO\n", __func__); \ return; \ } \