From patchwork Thu Jun 16 09:59:20 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 70164 Delivered-To: patch@linaro.org Received: by 10.140.28.4 with SMTP id 4csp174045qgy; Thu, 16 Jun 2016 02:59:32 -0700 (PDT) X-Received: by 10.98.79.194 with SMTP id f63mr4192820pfj.95.1466071172171; Thu, 16 Jun 2016 02:59:32 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q66si5238261pfi.216.2016.06.16.02.59.31; Thu, 16 Jun 2016 02:59:32 -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 S1753853AbcFPJ7b (ORCPT + 4 others); Thu, 16 Jun 2016 05:59:31 -0400 Received: from mail-lf0-f47.google.com ([209.85.215.47]:34599 "EHLO mail-lf0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751681AbcFPJ7a (ORCPT ); Thu, 16 Jun 2016 05:59:30 -0400 Received: by mail-lf0-f47.google.com with SMTP id j7so37135693lfg.1 for ; Thu, 16 Jun 2016 02:59:29 -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; bh=1qB2qpaMTt3cN/hRUleFP4zhbmDJbmkTDCNpJN8B1tk=; b=Gsbu0Ya7aUhmUTXyeoiFJbrdMAhOdZ8hJXuBaqz/RmeTb70bMt2hnLdz9qhmaxG3Z3 XLt0XKu4oMyNjPBeYHh2/ZJIHS15szis9mYW8pYTPM0kxXpZItxlEexkvPbAAt8CK/Oz me3GDyCe649cwY9RWGoERnXx6LtHAZAQNZ8ss= 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; bh=1qB2qpaMTt3cN/hRUleFP4zhbmDJbmkTDCNpJN8B1tk=; b=IdO58qKI5ScpbPX7+V17gJjWNvQIGVzmV8iLtyNcNSHMKNwkbqrBCfh4DQIRAR9UIM puL35y+MZZI6Q829ybuYUERp+QprW/nQmLzO4RjXB765kWJDZBudq9qYoiR4C435WChJ 350d4IZ69a5jEP6xvYwSxWz903WBLjXbatXCOobWtrVJxT1o8J6igfEywHZtOjL0xcp6 rMoAfXYyzil4/NZ84TV7ya4k72XVvBz/anwuuCVvuaNdVtui1P2vwBCVBodau/oKDjS6 8k40DFX6k9c8rzhlVyxSTGhCWjy3j6RuThy/JZZ3b8MPFEJZTQOAzVM4Jf8lLcFwKW1u ptng== X-Gm-Message-State: ALyK8tKVvUiRDoVPbb+WzHF9S7ij6h0T0go7GZN4LTnfsjUJ02Wn//R8h+XpVBNdp343DDuv X-Received: by 10.25.44.148 with SMTP id s142mr1046836lfs.146.1466071168369; Thu, 16 Jun 2016 02:59:28 -0700 (PDT) Received: from localhost.localdomain.localdomain (c-cc7c71d5.014-348-6c756e10.cust.bredbandsbolaget.se. [213.113.124.204]) by smtp.gmail.com with ESMTPSA id h31sm3980642ljh.29.2016.06.16.02.59.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 Jun 2016 02:59:27 -0700 (PDT) From: Linus Walleij To: linux-gpio@vger.kernel.org, Alexandre Courbot , Grygorii Strashko Cc: Linus Walleij , stable@vger.kernel.org Subject: [PATCH] gpio: make library immune to error pointers Date: Thu, 16 Jun 2016 11:59:20 +0200 Message-Id: <1466071160-16722-1-git-send-email-linus.walleij@linaro.org> X-Mailer: git-send-email 2.4.11 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Most functions that take a GPIO descriptor in need to check the descriptor for IS_ERR(). We do this mostly in the VALIDATE_DESC() macro except for the gpiod_to_irq() function which needs special handling. Cc: stable@vger.kernel.org Reported-by: Grygorii Strashko Signed-off-by: Linus Walleij --- drivers/gpio/gpiolib.c | 6 +++--- 1 file changed, 3 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 f39bf05993e7..1a8dbc791892 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -1371,7 +1371,7 @@ done: * optional GPIO and calls should just bail out. */ #define VALIDATE_DESC(desc) do { \ - if (!desc) \ + if (!desc || IS_ERR(desc)) \ return 0; \ if (!desc->gdev) { \ pr_warn("%s: invalid GPIO\n", __func__); \ @@ -1384,7 +1384,7 @@ done: } } while (0) #define VALIDATE_DESC_VOID(desc) do { \ - if (!desc) \ + if (!desc || IS_ERR(desc)) \ return; \ if (!desc->gdev) { \ pr_warn("%s: invalid GPIO\n", __func__); \ @@ -2061,7 +2061,7 @@ int gpiod_to_irq(const struct gpio_desc *desc) * requires this function to not return zero on an invalid descriptor * but rather a negative error number. */ - if (!desc || !desc->gdev || !desc->gdev->chip) + if (!desc || IS_ERR(desc) || !desc->gdev || !desc->gdev->chip) return -EINVAL; chip = desc->gdev->chip;