From patchwork Wed Jun 15 21:03:24 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 70129 Delivered-To: patch@linaro.org Received: by 10.140.106.246 with SMTP id e109csp54124qgf; Wed, 15 Jun 2016 14:03:35 -0700 (PDT) X-Received: by 10.36.40.204 with SMTP id h195mr2339700ith.69.1466024615286; Wed, 15 Jun 2016 14:03:35 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t123si1230297pfb.239.2016.06.15.14.03.34; Wed, 15 Jun 2016 14:03:35 -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 S932849AbcFOVDe (ORCPT + 4 others); Wed, 15 Jun 2016 17:03:34 -0400 Received: from mail-lf0-f44.google.com ([209.85.215.44]:34076 "EHLO mail-lf0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932084AbcFOVDd (ORCPT ); Wed, 15 Jun 2016 17:03:33 -0400 Received: by mail-lf0-f44.google.com with SMTP id j7so28225089lfg.1 for ; Wed, 15 Jun 2016 14:03:32 -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=5z7xrB1tCxmvVTEZXJHW6LSDlA+Qc+sQx5R20bzQLWQ=; b=MWeiH5ST66Xo2JMqsG/acr0X90jx+mfwlPp6Ixst6xaZGVRYsZVMsXJDypeh2BLRVC +y+b1GxOQKUyqjglFnJqEG3523fP92g/tSAFenmeCUtFUrywgmeCciIMrRRU9Jir7rUa DsYxjZFqkrFHYrVjS/+CwQkk3oFOD1WclrLjc= 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=5z7xrB1tCxmvVTEZXJHW6LSDlA+Qc+sQx5R20bzQLWQ=; b=R+ZbjKYbIM8Lom8NHffSu1hkudT/NwR2uA8z8PSIzNzmua6Rs9bHWkhPKCR8FMRDeq XzKLK/JCb9ORcceVB9OGCTziGWLUfEtSdBsIGbZAn0OZ7AJtGQBTz107tdPw4Hujky0y wTdxdYc4NCVLmRHES8tdejIHcKfbOlfn2Gclj8h1jdpmBuiySHe77/22TyCR/6TGKOZW TAFrjlDKSJ0htsplmjjqZaRsp+uKGGt8ZCb+f1aEdrgpBVHKuN7gKs/uy1Y/8RThp0Iy RWY/JU74kyv19vy3/5m+UaPYFr0DZrRq8SCvJ6niZZpXevdI78zAbHpKTl0Ba6uueV1z QH5Q== X-Gm-Message-State: ALyK8tKQz1kAjORzX8+CQgHJKLb7tFXmIQv0pjWrX8ZAOtxTbwVo69jxnA1X0+y9DkodY7AR X-Received: by 10.46.9.148 with SMTP id 142mr233794ljj.4.1466024611759; Wed, 15 Jun 2016 14:03:31 -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 89sm1165830lja.35.2016.06.15.14.03.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 15 Jun 2016 14:03:30 -0700 (PDT) From: Linus Walleij To: linux-gpio@vger.kernel.org, Alexandre Courbot , Hans de Goede Cc: Linus Walleij , Maxime Ripard Subject: [PATCH] gpio: make sure gpiod_to_irq() returns negative on NULL desc Date: Wed, 15 Jun 2016 23:03:24 +0200 Message-Id: <1466024604-28014-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 commit 54d77198fdfbc4f0fe11b4252c1d9c97d51a3264 ("gpio: bail out silently on NULL descriptors") doesn't work for gpiod_to_irq(): drivers assume that NULL descriptors will give negative IRQ numbers in return. It has been pointed out that returning 0 is NO_IRQ and that drivers should be amended to treat this as an error, but that is for the longer term: now let us repair the semantics. Cc: Maxime Ripard Reported-by: Hans de Goede Signed-off-by: Linus Walleij --- drivers/gpio/gpiolib.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) -- 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 58d822d7e8da..f39bf05993e7 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -2056,7 +2056,14 @@ int gpiod_to_irq(const struct gpio_desc *desc) struct gpio_chip *chip; int offset; - VALIDATE_DESC(desc); + /* + * Cannot VALIDATE_DESC() here as gpiod_to_irq() consumer semantics + * requires this function to not return zero on an invalid descriptor + * but rather a negative error number. + */ + if (!desc || !desc->gdev || !desc->gdev->chip) + return -EINVAL; + chip = desc->gdev->chip; offset = gpio_chip_hwgpio(desc); if (chip->to_irq) {