From patchwork Thu Dec 2 13:40:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 519942 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 0E1EAC433F5 for ; Thu, 2 Dec 2021 13:40:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1358274AbhLBNoB (ORCPT ); Thu, 2 Dec 2021 08:44:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1358266AbhLBNoA (ORCPT ); Thu, 2 Dec 2021 08:44:00 -0500 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 257D2C06174A for ; Thu, 2 Dec 2021 05:40:38 -0800 (PST) Received: by mail-wr1-x42d.google.com with SMTP id o13so59607365wrs.12 for ; Thu, 02 Dec 2021 05:40:38 -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=b8M7HnErTzGwfPKIGM3WgeLbmJVNvtClVXvn5c0S3W8=; b=DnV3vaBl+7005Uacj02nRKFbUAuRZKltmjfINz5Cn+wUzEQpqwjYO+0IEFqS0Qa5Gt jho7KqV+TPahR/FyCDy0RKIFJkKUdkchZBxv5rPg6dLQTtNKZEI8h/p5Pl2VIAPpQTt/ p/36Y96Lmkk7LZE3472yUs1/l+5uJYqgaLf6k+iUvVyofoyzSyU1o6WDKxG/KjnPQ11V THkRb1/azRXVfm3BRXqxhW+LIrjfW4RkJrZQHthPNZXfkWyXYQSB1nAH1TiDja2ztM7T JD/vlTAJTFCb5WJaipl1aIlRYQSRPuwJdWPpG9ewd1Cw6ZOm8ru7u1s3wmWG7o4S0i93 go7Q== 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=b8M7HnErTzGwfPKIGM3WgeLbmJVNvtClVXvn5c0S3W8=; b=vHm5DAuFH5fjmr+q5f8uPAzsKb81Pn609lcAJH5QaneEU1wUmGnC3xDWR7DaDT5qGT dpCcQk4GJAh0hi+5JT6hzNAqBq4V/4I0FwZdm3odhMFdgboY95TYtTUllvxug65TtQLn 830+gktgQI4m80JkIfcslPdZqtVisyg5gXxM5cqYRiNHxwi+i7WRsmOME6lqtGGTM3VK c0CS437APw3kpLtDEippOZrLqhLghGsXElhfyFxtX8193rjTP0EsnBvKoKSaxznq1d+y Rw0lRmWJklTX0Kdkdri4rtraiB998KYD6BYRwelW/dqCzWwgIS+zvW1MEvQ3i9mkVsk0 5HYQ== X-Gm-Message-State: AOAM531EwgV5UuchQ0IwxUEfM/W2nXrxwuPMpr0Dr9lFwup/vDGBnZyl zo45ydbqfyWL2kDIUl9KQEwhzw== X-Google-Smtp-Source: ABdhPJyv5uINR4hQfKWREIrTPJNfPf9WecEFFnwk8K0WPxIQsfqo3pKnDUnp4oXymCES7dAlA9jPvg== X-Received: by 2002:a05:6000:15c6:: with SMTP id y6mr14711300wry.422.1638452436588; Thu, 02 Dec 2021 05:40:36 -0800 (PST) Received: from debian-brgl.home ([2a01:cb1d:334:ac00:7d50:ff5:f5c1:e225]) by smtp.gmail.com with ESMTPSA id x13sm2660590wrr.47.2021.12.02.05.40.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Dec 2021 05:40:35 -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 v4 1/2] gpiolib: improve coding style for local variables Date: Thu, 2 Dec 2021 14:40:33 +0100 Message-Id: <20211202134034.14048-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 Reviewed-by: Andy Shevchenko --- v1 -> v2: - no changes v2 -> v3: - keep initializations on separate lines v3 -> v4: - no changes 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 Thu Dec 2 13:40:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 520370 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 E416EC433EF for ; Thu, 2 Dec 2021 13:40:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1358278AbhLBNoC (ORCPT ); Thu, 2 Dec 2021 08:44:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53720 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1358269AbhLBNoB (ORCPT ); Thu, 2 Dec 2021 08:44:01 -0500 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C9A52C061758 for ; Thu, 2 Dec 2021 05:40:38 -0800 (PST) Received: by mail-wr1-x42d.google.com with SMTP id u1so59717075wru.13 for ; Thu, 02 Dec 2021 05:40:38 -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=t/zjxVoZQh++FPpbJ/CZnvxguhK2M34uqFGsoutqJOs=; b=QHuxgQ3OEeVvQKCD8zkc7wkuya4ZofcO4drj/2f5m8xI57DSdCJ4DByBgWyLd+ElyR Mqjb32vFI475BQ9ppsyqvDA7Kwl5gkp7b3VB71BSJqE9AV72y67zEKItNtcCAuqn/jZY XGzhESVMFy1djJo57XajNnU/2kQ0wfVxX1fDsrjqqmpoWtydF6yPAvCfhosd2MPiqgDa ntw0DxFl6AnS4QJb9vjI+91gIMSBBPSZrT5EV/V35n00kqlbyN1xKG8o9psTXTQeeE+6 EFjpbLksmko98uzE6qVEEoNvjBsBos2tGcv1HQlBfzgfUJB8kxwqk0VkYMfiJGPi1NN0 q6Fw== 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=t/zjxVoZQh++FPpbJ/CZnvxguhK2M34uqFGsoutqJOs=; b=a+6Gddg8yDWInGZBlEd5d2ZHrEML6VuAgPovbTeFOy7dK0BGULo/6WFaiPY6mjp8Vf 8ecy5UdhD5zpUb+BN2EDh+P+syzjVapadJW9AjqOYs/Aq2CzJQpOyV4QjUVJz2bZvRpM 9jA+3OJb28gDCuewwUnXNFDKBV+7NfaewYLeYWNoh5TZrizvMwocbHP60V2ulFB0kVJh pD0cOst1Noh+v+OQsMS+fjjSvYaASqzxl8iW5lC3bQu1qBmz4gJLa6YUxgaSpOcpNv/J ktU4t0XekwQHitagAH8Enh1J/BJgO8zlOzyTsRumUuRTlC8GWNzPjWJS7RLXXFd+2y7H h/Fw== X-Gm-Message-State: AOAM532CRBTfRJkKd0SVqcGPxFBRURvtfwGaRxYMcXBS768sojyixf3q ow/T8A2Dbq4JzhYGW35F/znS44UnjXbPi/o/ X-Google-Smtp-Source: ABdhPJy36F01foZeGeqTbCOZ1V0AxIhVD+1OtHsq9HLzzkTDzMVwAw1CS1fr94wx2VwYv692WVVB6A== X-Received: by 2002:adf:a193:: with SMTP id u19mr14648689wru.563.1638452437319; Thu, 02 Dec 2021 05:40:37 -0800 (PST) Received: from debian-brgl.home ([2a01:cb1d:334:ac00:7d50:ff5:f5c1:e225]) by smtp.gmail.com with ESMTPSA id x13sm2660590wrr.47.2021.12.02.05.40.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Dec 2021 05:40:37 -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 v4 2/2] gpiolib: check the 'ngpios' property in core gpiolib code Date: Thu, 2 Dec 2021 14:40:34 +0100 Message-Id: <20211202134034.14048-2-brgl@bgdev.pl> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20211202134034.14048-1-brgl@bgdev.pl> References: <20211202134034.14048-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() v3 -> v4: - also make sure we return -EINVAL when the device 'ngpios' property is set to 0 (thanks Andy!) drivers/gpio/gpiolib.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index ede8b8a7aa18..bd9b8cb53476 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 @@ -646,6 +647,26 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data, goto err_free_dev_name; } + /* + * Try the device properties if the driver didn't supply the number + * of GPIO lines. + */ + if (gc->ngpio == 0) { + ret = device_property_read_u32(&gdev->dev, "ngpios", &ngpios); + if (ret == -ENODATA) + /* + * -ENODATA means that there is no property found and + * we want to issue the error message to the user. + * Besides that, we want to return different error code + * to state that supplied value is not valid. + * */ + ngpios = 0; + else if (ret) + goto err_free_descs; + + gc->ngpio = ngpios; + } + if (gc->ngpio == 0) { chip_err(gc, "tried to insert a GPIO chip with zero lines\n"); ret = -EINVAL;