Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp873485pxb; Tue, 1 Feb 2022 12:10:54 -0800 (PST) X-Google-Smtp-Source: ABdhPJxlxzOZ/L+Tk2WiCSgIMT2y8YcQ+5yCysdZ0/mBzgTOE6iYwQ87loXBf3kuGh14xS6Ub39F X-Received: by 2002:a17:903:11c3:: with SMTP id q3mr27428527plh.97.1643746253905; Tue, 01 Feb 2022 12:10:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643746253; cv=none; d=google.com; s=arc-20160816; b=xgOwGu1dFouSBWP9ak0IEIaZ6BMkN75oJel9GNFXbJ/qnyz4qYdjF2YkwadhKP24h+ 4MKHiATgGxvSXJd/qxDBNz35Un9ZHhnhAFDQDTC3BvyliEuvcvBrMKPOExN4uGxcy4qE ik80tDSjbwHtzcWTNm4yr8DG+B6GXve/Tg4fu3nxnDcB6BmAgoSvC26N673QjLm/T6+2 wmAcV84ZKEIvHp84oaytvnku1VxKuC/Uzj9P9K0CIsi7s9S53rP6aqwvwcx9Bdkt/yt1 J7B0uxfYIe78MSdCrWEjNEpDJ6y2+4ReHWpUlenU0eyOO/P3zSUPorptFQACzoFYm7nk LhsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=6zTwOe+LFGj8K9CozwrVFPK9mx9b/MrgscopzU6MQYk=; b=DulK7Vt9yrp7DB6CzqBffnO0AjN8wM8MkHZ4bjc5W4H8hOLkZWO+2yjG4Lw9c+poDd txBCYVvYZFukU+y1z/h03W7DtltnOS4C/nRGHrunN4gK9Xqx+G2Sr2dF6N811j4GJYIS mpuPlhU40Jq1H0+F7TmpKhbiUw0RJQf3fx4U/YCd4Z320Y0kJhH/9knGBk0EClhBIHa5 d3rBaw8uiIXrPJcg8PAId2SFsr3O9sTdZNcZgh9LruZc7L7vKuCN7Ebhoc4cZfk00fK/ S1pRQgg5v64pgrzhxJ57CtV+pkOux0Qm2Kwk/SIblx6FK7n82zN5PWEXJ1wIus2pEp7L XUEQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u1si3047383pjd.150.2022.02.01.12.10.41; Tue, 01 Feb 2022 12:10:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376645AbiAaLky (ORCPT + 99 others); Mon, 31 Jan 2022 06:40:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50236 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379405AbiAaLaR (ORCPT ); Mon, 31 Jan 2022 06:30:17 -0500 Received: from baptiste.telenet-ops.be (baptiste.telenet-ops.be [IPv6:2a02:1800:120:4::f00:13]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A65C2C0617AD for ; Mon, 31 Jan 2022 03:20:07 -0800 (PST) Received: from ramsan.of.borg ([IPv6:2a02:1810:ac12:ed40:58b3:216b:d287:833]) by baptiste.telenet-ops.be with bizsmtp id pPL3260072lsq0X01PL3R0; Mon, 31 Jan 2022 12:20:03 +0100 Received: from rox.of.borg ([192.168.97.57]) by ramsan.of.borg with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1nEUj4-00CZlM-Sc; Mon, 31 Jan 2022 12:20:02 +0100 Received: from geert by rox.of.borg with local (Exim 4.93) (envelope-from ) id 1nEU2M-00GXJ8-EI; Mon, 31 Jan 2022 11:35:54 +0100 From: Geert Uytterhoeven To: Linus Walleij , Bartosz Golaszewski , =?UTF-8?q?Mikko=20Salom=C3=A4ki?= Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH] gpio: aggregator: Fix calling into sleeping GPIO controllers Date: Mon, 31 Jan 2022 11:35:53 +0100 Message-Id: <6a62a531227cd4f20d77d50cdde60c7a18b9f052.1643625325.git.geert+renesas@glider.be> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If the parent GPIO controller is a sleeping controller (e.g. a GPIO controller connected to I2C), getting or setting a GPIO triggers a might_sleep() warning. This happens because the GPIO Aggregator takes the can_sleep flag into account only for its internal locking, not for calling into the parent GPIO controller. Fix this by using the gpiod_[gs]et*_cansleep() APIs when calling into a sleeping GPIO controller. Reported-by: Mikko Salomäki Fixes: 828546e24280f721 ("gpio: Add GPIO Aggregator") Signed-off-by: Geert Uytterhoeven --- I considered splitting the .[gs]et{_multiple}() callbacks for the sleeping vs. nonsleeping cases, but the code size increase (measured on ARM) would be substantial: +64 bytes for gpio_fwd_[gs]et_cansleep(), +296 bytes for gpio_fwd_[gs]et_multiple_cansleep(). --- drivers/gpio/gpio-aggregator.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/drivers/gpio/gpio-aggregator.c b/drivers/gpio/gpio-aggregator.c index 869dc952cf45218b..0cb2664085cf8314 100644 --- a/drivers/gpio/gpio-aggregator.c +++ b/drivers/gpio/gpio-aggregator.c @@ -278,7 +278,8 @@ static int gpio_fwd_get(struct gpio_chip *chip, unsigned int offset) { struct gpiochip_fwd *fwd = gpiochip_get_data(chip); - return gpiod_get_value(fwd->descs[offset]); + return chip->can_sleep ? gpiod_get_value_cansleep(fwd->descs[offset]) + : gpiod_get_value(fwd->descs[offset]); } static int gpio_fwd_get_multiple(struct gpiochip_fwd *fwd, unsigned long *mask, @@ -293,7 +294,10 @@ static int gpio_fwd_get_multiple(struct gpiochip_fwd *fwd, unsigned long *mask, for_each_set_bit(i, mask, fwd->chip.ngpio) descs[j++] = fwd->descs[i]; - error = gpiod_get_array_value(j, descs, NULL, values); + if (fwd->chip.can_sleep) + error = gpiod_get_array_value_cansleep(j, descs, NULL, values); + else + error = gpiod_get_array_value(j, descs, NULL, values); if (error) return error; @@ -328,7 +332,10 @@ static void gpio_fwd_set(struct gpio_chip *chip, unsigned int offset, int value) { struct gpiochip_fwd *fwd = gpiochip_get_data(chip); - gpiod_set_value(fwd->descs[offset], value); + if (chip->can_sleep) + gpiod_set_value_cansleep(fwd->descs[offset], value); + else + gpiod_set_value(fwd->descs[offset], value); } static void gpio_fwd_set_multiple(struct gpiochip_fwd *fwd, unsigned long *mask, @@ -343,7 +350,10 @@ static void gpio_fwd_set_multiple(struct gpiochip_fwd *fwd, unsigned long *mask, descs[j++] = fwd->descs[i]; } - gpiod_set_array_value(j, descs, NULL, values); + if (fwd->chip.can_sleep) + gpiod_set_array_value_cansleep(j, descs, NULL, values); + else + gpiod_set_array_value(j, descs, NULL, values); } static void gpio_fwd_set_multiple_locked(struct gpio_chip *chip, -- 2.25.1