From patchwork Thu Jun 16 11:22:37 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 70180 Delivered-To: patch@linaro.org Received: by 10.140.28.4 with SMTP id 4csp206384qgy; Thu, 16 Jun 2016 04:22:48 -0700 (PDT) X-Received: by 10.66.249.161 with SMTP id yv1mr4494777pac.39.1466076167699; Thu, 16 Jun 2016 04:22:47 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id fj5si5411747pad.96.2016.06.16.04.22.47; Thu, 16 Jun 2016 04:22:47 -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 S1754486AbcFPLWp (ORCPT + 4 others); Thu, 16 Jun 2016 07:22:45 -0400 Received: from mail-lf0-f44.google.com ([209.85.215.44]:36182 "EHLO mail-lf0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754310AbcFPLWn (ORCPT ); Thu, 16 Jun 2016 07:22:43 -0400 Received: by mail-lf0-f44.google.com with SMTP id q132so38358353lfe.3 for ; Thu, 16 Jun 2016 04:22:42 -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=5BxhelLx/HisU+T/DY5PlMMak5AkogmpkHiOs3U5WQk=; b=L5qLIacnp32RXuRgSqmYLi7W8IvfC3+Lkk1+8H/DTFQZHrxjIWX4tUWRaPLsDlx5BC oAhDsivVVeU/L8kbF8Y2K6iLa9udOseP80+Gug080L2Nk1WErIlS/2Wv2ewIVE19+8a3 AhaX2JPgnI/CvpPFtQM9DTef765ViJ7U/Noxc= 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=5BxhelLx/HisU+T/DY5PlMMak5AkogmpkHiOs3U5WQk=; b=UIZXrg6PB8s9lhPn+VVNO3/8I/TIJzOEWsTa2wYGZnokcLYTOJd4P03SJ6xEezz84f TPmOy5wpWBR01/iijA1/E97ARFOjCXgZ7wCz2ob2h7EvNRKGGcQCeAGtJpqid9bJxXQN sBiTO2HuYNugGu6KQCVfuwdO90IvMQvOT4ROa3JTTwqiuiuLCJv055lky2FezBFNC6+m XKBgZN6WrqVfVl3NxBNYeH9iqq31iDFASrNyqBsEqSc2tlqgQGFxhKugQdnV86dQY6f0 zThTLgbC4fZW98lzf9VaZZkMexmNt3oW7NedpXL1sZn+IUCez8FF9KjWZ5hR52WqON1R 9FzQ== X-Gm-Message-State: ALyK8tIsK0SfZnuoiZG6puFt0NT0NDL/2FDkG596nXzDEnkzX0PDPGdR5Pr4KE8565cTkbwt X-Received: by 10.25.19.211 with SMTP id 80mr957038lft.147.1466076161374; Thu, 16 Jun 2016 04:22:41 -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 e41sm3862455lji.42.2016.06.16.04.22.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 Jun 2016 04:22:39 -0700 (PDT) From: Linus Walleij To: linux-gpio@vger.kernel.org, Alexandre Courbot , Grygorii Strashko Cc: Linus Walleij , stable@vger.kernel.org Subject: [PATCH v2] gpio: make library immune to error pointers Date: Thu, 16 Jun 2016 13:22:37 +0200 Message-Id: <1466076157-9805-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 --- ChangeLog v1->v2: - Complain when descriptors contain error values so the offending code can be fixed. --- drivers/gpio/gpiolib.c | 14 +++++++++++--- 1 file changed, 11 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..570771ed19e6 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -1373,8 +1373,12 @@ done: #define VALIDATE_DESC(desc) do { \ if (!desc) \ return 0; \ + if (IS_ERR(desc)) { \ + pr_warn("%s: invalid GPIO (errorpointer)\n", __func__); \ + return PTR_ERR(desc); \ + } \ if (!desc->gdev) { \ - pr_warn("%s: invalid GPIO\n", __func__); \ + pr_warn("%s: invalid GPIO (no device)\n", __func__); \ return -EINVAL; \ } \ if ( !desc->gdev->chip ) { \ @@ -1386,8 +1390,12 @@ done: #define VALIDATE_DESC_VOID(desc) do { \ if (!desc) \ return; \ + if (IS_ERR(desc)) { \ + pr_warn("%s: invalid GPIO (errorpointer)\n", __func__); \ + return; \ + } \ if (!desc->gdev) { \ - pr_warn("%s: invalid GPIO\n", __func__); \ + pr_warn("%s: invalid GPIO (no device)\n", __func__); \ return; \ } \ if (!desc->gdev->chip) { \ @@ -2061,7 +2069,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;