From patchwork Wed Nov 24 12:28:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 517102 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2784EC433F5 for ; Wed, 24 Nov 2021 14:14:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351431AbhKXORs (ORCPT ); Wed, 24 Nov 2021 09:17:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44448 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352900AbhKXORR (ORCPT ); Wed, 24 Nov 2021 09:17:17 -0500 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 95F00C0818F0 for ; Wed, 24 Nov 2021 04:28:56 -0800 (PST) Received: by mail-wr1-x435.google.com with SMTP id l16so3873764wrp.11 for ; Wed, 24 Nov 2021 04:28:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=itVP4aNbik/dROJTIOMt1U3nLqJ1tEkeMNd95tsUZfI=; b=MDUIPdijTyP4/fpQuv6ZuVlM7tyrXL9fEM9D1engdJP3v/7I6HXcc4tq3W05xa282v 7MfuuDChpc2dk2IRy9XzTmqZZUZluuJu0ybfxkEN0VPtlboCLZ9Pe/NYIlieWYqYRXa2 zQlZcgiu9HQw8pQYEwWLpqvKAljYvRUkNuZNWA3QxluesS3L5jcmU1RSGMf8gLUfR4RP XEKjcO0Sxi5XsOHlZPKE8l696doVzC4K0qFZ+SmW4GA6XCt5uzXH+FG8C7NiCcQimAnO dFQhZwxQ1vdoxp28sQxtbV0ROhqtvzmJTxUQWik3oKpeLmH9xCtN4OOOwQfnrX6Hluqj loPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=itVP4aNbik/dROJTIOMt1U3nLqJ1tEkeMNd95tsUZfI=; b=fOOCV76/FRVSleSCAO7asKFaDbcgwaaWlZ728W96tiEc+40RxIfUWsGR/UZls9XaZv KfuyX6w5uSUvAZgEek6eNowF2QO8jL4UvVY32ti8uZ/2P2gY9eHNRL+IMvhGduxFpE3W ihqFmffU6bj5AQQ04WsDXsT66XYbN4gBxd5InbEdOLq99/DOcBPiXKZV/NoerJnbn/Tx 9AhgPkxx5OKURks/5y8jDnkQEwzswSz5SXJnOjSDMCssrR4wYL7PTOyGgA+x9TZNgBJC xCRf2ex1Xhuc/LECWRN6LtuQraiTZsvnBGhWr72faQSwuLQVzrqbNIMaGpxReqJTxDPZ t5Uw== X-Gm-Message-State: AOAM5319EGvNMcRoxfAklsH8GXtEsw8w+3N/3PjJP8nfK+gEElEmxCCZ kM0QKgM8t2winWCEA9Pw16WrQQ== X-Google-Smtp-Source: ABdhPJxI1/vhZ1KM2jJH6ksA70uIiYHjkzcyEe/prqKG2CyKBGHpDy10UuCc8LzOuo7Pl0GG8bMXbQ== X-Received: by 2002:a5d:45c4:: with SMTP id b4mr18470805wrs.222.1637756935206; Wed, 24 Nov 2021 04:28:55 -0800 (PST) Received: from debian-brgl.home ([2a01:cb1d:334:ac00:7d50:ff5:f5c1:e225]) by smtp.gmail.com with ESMTPSA id p62sm4417694wmp.10.2021.11.24.04.28.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Nov 2021 04:28:54 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Andy Shevchenko , Johan Hovold Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v3 1/2] gpiolib: improve coding style for local variables Date: Wed, 24 Nov 2021 13:28:49 +0100 Message-Id: <20211124122850.7095-1-brgl@bgdev.pl> X-Mailer: git-send-email 2.30.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Drop unneeded whitespaces and put the variables of the same type together for consistency with the rest of the code. Signed-off-by: Bartosz Golaszewski Reviewed-by: Linus Walleij --- v1 -> v2: - keep initializations on separate lines drivers/gpio/gpiolib.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index abfbf546d159..ede8b8a7aa18 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -594,11 +594,11 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data, struct lock_class_key *request_key) { struct fwnode_handle *fwnode = gc->parent ? dev_fwnode(gc->parent) : NULL; - unsigned long flags; - int ret = 0; - unsigned i; - int base = gc->base; struct gpio_device *gdev; + unsigned long flags; + int base = gc->base; + unsigned int i; + int ret = 0; /* * First: allocate and populate the internal stat container, and From patchwork Wed Nov 24 12:28:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 518396 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 08AC1C433EF for ; Wed, 24 Nov 2021 14:14:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348868AbhKXOSC (ORCPT ); Wed, 24 Nov 2021 09:18:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44038 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351000AbhKXOR1 (ORCPT ); Wed, 24 Nov 2021 09:17:27 -0500 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 36F98C0818F3 for ; Wed, 24 Nov 2021 04:28:57 -0800 (PST) Received: by mail-wm1-x331.google.com with SMTP id p27-20020a05600c1d9b00b0033bf8532855so1910680wms.3 for ; Wed, 24 Nov 2021 04:28:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=DcZ1Q8d+O6FgM0ahJ1NKmjZFVwY2xw4s/RvlwwiK+mU=; b=WOKeoFFzUWyCB51Qa2QJzo4p0Sv9PqYAsGJHScNWi0Nxq4TkivGBjOMsmIQgYB/l3P rB4/KYGerJym8yts+yBeedP3jrVFUZLq8OQZLErIvNzv7MK1wT7l35NbDKJ5VmFA9Dus 9H8JlOuZ+ZuUTWSev2rzR576dLdVH29+YiWKHTd8sSyawZ9p/i8GxRJ9sIIAdYpnO58S yKpT2i+cBPy1bC9Zg78RgvmKXjZvkYtiItvAhlvZIp8Fta8qs91Xwgbh4DPIpyK3Df4E QENJwb+fp+kPKHGoW6R3OYrgOjIGHkGW9INfjPhGlP7bYiFpbXDKLdNYhVUoKu1z1YfA mCJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DcZ1Q8d+O6FgM0ahJ1NKmjZFVwY2xw4s/RvlwwiK+mU=; b=8ORRcrscAlBwT6bdxWUX+ILFlRMOw2mZqYEOO47RkRgfGBo1SAfrA3aO856Swc0Rd/ inP7BphPKXqx8Cxki3yf4LRILPYRloBvG6hfpUT0KtpYrbNmEedyehtF27m+AE22mNfb TJtBCfPGnqNWvm9VS0ivTf5aZHiRR3T7wC8bh/UQMi2AafOKvEv3KKKfsbsDB0eJ0L6o YXmlzE7YM2WURQg2I5WGan739e+kBacV+TnFh+kCAZjWgrGND/7z2URi/m2v44Jo7vwK qK0+IrznzhrHZUtSx5xYy2drvSId6jjPXPVRwd4qP+JEwJvj6wZ9GNMEyuFJr4XCXk8N OJCg== X-Gm-Message-State: AOAM531ayPAfWv+F8MEsS7hj12j7DSRwBlHHsW8NnwqSuBFj4ISbSW2M rR+hhr+yzinq0fYTH3LhfaJDWLK5yEGe8zTe X-Google-Smtp-Source: ABdhPJzT/jKV/kTbp1ET/jbz8/YdJAG86C5Bkz7yhjB8UEXLmD/yNJcyuAzmYfO/v9dZHELp43N/GA== X-Received: by 2002:a05:600c:22d9:: with SMTP id 25mr14255425wmg.71.1637756935782; Wed, 24 Nov 2021 04:28:55 -0800 (PST) Received: from debian-brgl.home ([2a01:cb1d:334:ac00:7d50:ff5:f5c1:e225]) by smtp.gmail.com with ESMTPSA id p62sm4417694wmp.10.2021.11.24.04.28.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Nov 2021 04:28:55 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Andy Shevchenko , Johan Hovold Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v3 2/2] gpiolib: check the 'ngpios' property in core gpiolib code Date: Wed, 24 Nov 2021 13:28:50 +0100 Message-Id: <20211124122850.7095-2-brgl@bgdev.pl> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20211124122850.7095-1-brgl@bgdev.pl> References: <20211124122850.7095-1-brgl@bgdev.pl> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Several drivers read the 'ngpios' device property on their own, but since it's defined as a standard GPIO property in the device tree bindings anyway, it's a good candidate for generalization. If the driver didn't set its gc->ngpio, try to read the 'ngpios' property from the GPIO device's firmware node before bailing out. Signed-off-by: Bartosz Golaszewski Suggested-by: Andy Shevchenko Reviewed-by: Linus Walleij --- v1 -> v2: - use device_property_read_u32() instead of fwnode_property_read_u32() - reverse the error check logic v2 -> v3: - don't shadow errors other than -ENODATA in device_property_read_u32() drivers/gpio/gpiolib.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index ede8b8a7aa18..f79fd2551cf7 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -599,6 +599,7 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data, int base = gc->base; unsigned int i; int ret = 0; + u32 ngpios; /* * First: allocate and populate the internal stat container, and @@ -647,9 +648,17 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data, } if (gc->ngpio == 0) { - chip_err(gc, "tried to insert a GPIO chip with zero lines\n"); - ret = -EINVAL; - goto err_free_descs; + ret = device_property_read_u32(&gdev->dev, "ngpios", &ngpios); + if (ret) { + if (ret == -ENODATA) { + chip_err(gc, "tried to insert a GPIO chip with zero lines\n"); + ret = -EINVAL; + } + + goto err_free_descs; + } + + gc->ngpio = ngpios; } if (gc->ngpio > FASTPATH_NGPIO)