Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp5311523ybc; Wed, 27 Nov 2019 02:01:37 -0800 (PST) X-Google-Smtp-Source: APXvYqwsDq5nft/BugYxOw+MIAWVhFlwhSxfknxaWSocfuD14NZgdAi/zYsoQ525B5G6Mmz/pcgh X-Received: by 2002:aa7:c68d:: with SMTP id n13mr25984472edq.193.1574848897399; Wed, 27 Nov 2019 02:01:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574848897; cv=none; d=google.com; s=arc-20160816; b=sJmZysngACs2ncv7TA9YnmEdhUAHtxLklFDcokMzLF9qAfxjSJpnSHH6TFlicbV9Lw W6NfMPkm3DXuSNflpHJiiOYWS3bhngPb1AlaMLHAv1IS/67TlJJR2CF8hmen3jUh6CuV PmeUyesRGlx+UrccLpBpjxrxZ2GTeVany91p/+EjGoSWxg/xWDRVX7gil0DwlJgbAK9y mNNQUyKs9moALvJ3xQUsNdFrlwQbqNmLd6WcEY/eON/iocf7+1Ab7n7qEkys5YSzm37c QIy3Y6QqwoVD3kpSZsY157fLDUPPAUj/SkKnn4q53dQdy6BwbmTshdRVl/4xOepoLGuS KPDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=WPMoJbfZ6/QmyUHhjeLVNPMoYeUCtfljZaAeeEJu9ms=; b=RUe+krcgyCKgZcg+gXD221SNEqbH3BYz/QHjuTOxuiEk5vFFHCzDDoLy3O9slOybaW z6vu12e/b3P6hEQUueUZnF3sLoU4xn6nY9R8qJ3TfguafJ2U6aRE5x5vTln5w+RyZ/oo VZI73XaReKZIB4ETl2faprPbrmntlvzBqj1DQs+LGYnhMcbNtfIPZgr8FlUyE24zfUng lpCe4o4Dn9hvpQyAirCnccVSn1YLpTForWzrrfD3SH/t+Yl8FrNpUwvkYoKUAIVELePz nocOQ7A8O/ve6oZyV/NAa49+t8edsgLo6FK8cypxFwsvzLj0rfowOCzEnv7pGU760Bna XK2Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w26si9327444ejn.212.2019.11.27.02.00.57; Wed, 27 Nov 2019 02:01:37 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726987AbfK0J7X (ORCPT + 99 others); Wed, 27 Nov 2019 04:59:23 -0500 Received: from baptiste.telenet-ops.be ([195.130.132.51]:52234 "EHLO baptiste.telenet-ops.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726133AbfK0J7X (ORCPT ); Wed, 27 Nov 2019 04:59:23 -0500 Received: from ramsan ([84.195.182.253]) by baptiste.telenet-ops.be with bizsmtp id WxzL2100c5USYZQ01xzL2C; Wed, 27 Nov 2019 10:59:20 +0100 Received: from rox.of.borg ([192.168.97.57]) by ramsan with esmtp (Exim 4.90_1) (envelope-from ) id 1iZu6S-0001tZ-L5; Wed, 27 Nov 2019 10:59:20 +0100 Received: from geert by rox.of.borg with local (Exim 4.90_1) (envelope-from ) id 1iZu6S-00016h-IZ; Wed, 27 Nov 2019 10:59:20 +0100 From: Geert Uytterhoeven To: Linus Walleij , Bartosz Golaszewski , Alexandre Courbot Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH] gpiolib: Fix error message on out-of-range GPIO in lookup table Date: Wed, 27 Nov 2019 10:59:19 +0100 Message-Id: <20191127095919.4214-1-geert+renesas@glider.be> X-Mailer: git-send-email 2.17.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When a GPIO offset in a lookup table is out-of-range, the printed error message (1) does not include the actual out-of-range value, and (2) contains an off-by-one error in the upper bound. Avoid user confusion by also printing the actual GPIO offset, and correcting the upper bound of the range. While at it, use "%u" for unsigned int. Sample impact: -requested GPIO 0 is out of range [0..32] for chip e6052000.gpio +requested GPIO 0 (45) is out of range [0..31] for chip e6052000.gpio Fixes: 2a3cf6a3599e9015 ("gpiolib: return -ENOENT if no GPIO mapping exists") Signed-off-by: Geert Uytterhoeven --- drivers/gpio/gpiolib.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 9913886ede904bb0..dce0b31f4125a6b3 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -4472,8 +4472,9 @@ static struct gpio_desc *gpiod_find(struct device *dev, const char *con_id, if (chip->ngpio <= p->chip_hwnum) { dev_err(dev, - "requested GPIO %d is out of range [0..%d] for chip %s\n", - idx, chip->ngpio, chip->label); + "requested GPIO %u (%u) is out of range [0..%u] for chip %s\n", + idx, p->chip_hwnum, chip->ngpio - 1, + chip->label); return ERR_PTR(-EINVAL); } -- 2.17.1