Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp743667pxa; Sat, 1 Aug 2020 04:53:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwuEMBBhYVDPjlo4ZNa/MUfNrbMTrq/eUGB51osa7qADFVxMYS/1sU9Q52SlcfEac5bw61S X-Received: by 2002:a17:906:d8f:: with SMTP id m15mr8170737eji.494.1596282807000; Sat, 01 Aug 2020 04:53:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596282806; cv=none; d=google.com; s=arc-20160816; b=gwN55uSmGwqkvw2GoD1bI9OVf17dOwmSXs5CL+ALGoBSWabQE5g4X+OHVGbWUUGg5/ i9i2/lfYWbZLOafrhW/ejpsuuNa5dPTuwINSU6NJ7DQGPvIi9ySmGfcwCkhQq/hZsnMC KjC3G2GlcyjM0j3f1fhTGz4qT6unPbr0U0Xt61d1Tq8aYDNLvjYnghJXv7iVvniR8vSB I4/lfFyjSYXfcj/zqS16pzxfkxw8J1E8J2M4qO/a5CnQG/WdrSGVNbVK4mOMl43cldqb E9VVoDC8GuA7JBF0vugcQO0Y9+hn0OGQlfJyjFazDEB+Z39s6efuh2jQlsjfPlCMwkn/ QlRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=h2cimN9Yvy25UPH51XSaIWZhhYkPPGceN+e4WaCDrxc=; b=e84433yzo5zB0DhLgcRW7CCKarvojVmQ2TYSJryLRbTfq6egJ1z44s50bQKOGm5G2x 3gpr6Q9OkhNGOKrT4rBRb1z8yO7HllSm2iaIPB1G5WtYUU+ZZ943TocchCoYzpvUfH8W 6qZ/z01Jn3Tdo2SDWowi8GERfflAr4gnix1pXgpKzie/mcBUynBfm/NpzSnyUIw5Hhtb fJzFgOKeA90XQIAvnsG6DGP7QyOoTUDy1Eqfil13ZsQrqeRUaIOIu8Pixd/tANdCa0C0 pehde4BujB+8wFvNZpeHCdS9VjgtKBnXDY4/rggJAeONsNLwEN4Wb3BXSMr6y1WSe5xB eLrA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="bH/7xYTV"; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b6si6769068edn.454.2020.08.01.04.53.04; Sat, 01 Aug 2020 04:53:26 -0700 (PDT) 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; dkim=pass header.i=@gmail.com header.s=20161025 header.b="bH/7xYTV"; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728889AbgHALwE (ORCPT + 99 others); Sat, 1 Aug 2020 07:52:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49268 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728505AbgHALwD (ORCPT ); Sat, 1 Aug 2020 07:52:03 -0400 Received: from mail-pj1-x1044.google.com (mail-pj1-x1044.google.com [IPv6:2607:f8b0:4864:20::1044]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 04A9AC06174A; Sat, 1 Aug 2020 04:52:03 -0700 (PDT) Received: by mail-pj1-x1044.google.com with SMTP id lx9so9006447pjb.2; Sat, 01 Aug 2020 04:52:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=h2cimN9Yvy25UPH51XSaIWZhhYkPPGceN+e4WaCDrxc=; b=bH/7xYTVSzAYcbVdRzs8gJFpprccPE4mejvVwACUZSyaK4y7HU0D4JgmpJieFGMzca By43QB0NUfbqvAw4PsJoN+Ka+Ac67V9IQ6ySwQVN3kmDMb5auEnBECTxFPziztvdXkBF 31lWDuJ4tH4zL5i2eokMS76E2FVS2yORWf5IHX0h6RA2qdyKnIMtpHSbt5i8rAwTTWv2 SBnXvJdgmVaSFQJDOk8imVfUnnqlOyfBVnYIH8Gg/JAMSzwZYnokzVlP80psyONL4+P0 k5+8HYB29ylJNQmSvVqkVp5zKe3zwzR5viY7ytlOQa69tkbQEOHw8fYGo1RUNlYl+U8T DlfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=h2cimN9Yvy25UPH51XSaIWZhhYkPPGceN+e4WaCDrxc=; b=D64GNYNAyyHz4jnGRc/WP8DMBV+5gHlf5wKwc5SbW+f31waxvjBAw4d4xEtSscxBeR Oa8FuOesyYf2EaUWidjtf5c275Ek3giHBgnA6gnvP4GXFONsSxRISYLIKdLZdHknQwGk 6vwoV1scrAOtgyve8bgNA8UgmG7InkROLoULyeGp9+fA/iMvhLGZQT9fPDDkMcuIXemk q9Tn5vEIziQ8StYyvo/HSB4ztzGRjoqo2T/8kSMz2MGvf/l3j56AjVYrGeSTY1cZSdud sGJBhmCoWruiliU7g5miSJGAKvc3/6RTlN7yO3zmXB09nHzEwPDpydy4jOvnuvzoUQfy e1qw== X-Gm-Message-State: AOAM531buHT1gBWAg4AvtPLuUdJJrgh838x7V77W05JEsMmaU1s3F4As gZkzF1d9kWSIc0B0Kar0p6lQASlRdETu7wj15AQ= X-Received: by 2002:a17:902:8491:: with SMTP id c17mr7322900plo.262.1596282722426; Sat, 01 Aug 2020 04:52:02 -0700 (PDT) MIME-Version: 1.0 References: <20200731123835.8003-1-a.fatoum@pengutronix.de> In-Reply-To: <20200731123835.8003-1-a.fatoum@pengutronix.de> From: Andy Shevchenko Date: Sat, 1 Aug 2020 14:51:46 +0300 Message-ID: Subject: Re: [PATCH] gpio: don't use same lockdep class for all devm_gpiochip_add_data users To: Ahmad Fatoum Cc: Linus Walleij , Bartosz Golaszewski , Grygorii Strashko , Thierry Reding , Sascha Hauer , "open list:GPIO SUBSYSTEM" , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jul 31, 2020 at 3:40 PM Ahmad Fatoum wrote: > > Commit 959bc7b22bd2 ("gpio: Automatically add lockdep keys") documents > in its commits message its intention to "create a unique class key for > each driver". > > It does so by having gpiochip_add_data add in-place the definition of > two static lockdep classes for LOCKDEP use. That way, every caller of > the macro adds their gpiochip with unique lockdep classes. > > There are many indirect callers of gpiochip_add_data, however, via > use of devm_gpiochip_add_data. devm_gpiochip_add_data has external > linkage and all its users will share the same lockdep classes, which > probably is not intended. > > Fix this by replicating the gpio_chip_add_data statics-in-macro for > the devm_ version as well. I ran into similar issues in another driver (not GPIO) and I agree with the fix. Reviewed-by: Andy Shevchenko > Fixes: 959bc7b22bd2 ("gpio: Automatically add lockdep keys") > Signed-off-by: Ahmad Fatoum > --- > This doesn't fix any particular problem I ran into, but the code > looked buggy, at least to my lockdep-user-not-developer eyes. > --- > drivers/gpio/gpiolib-devres.c | 13 ++++++++----- > include/linux/gpio/driver.h | 13 +++++++++++-- > 2 files changed, 19 insertions(+), 7 deletions(-) > > diff --git a/drivers/gpio/gpiolib-devres.c b/drivers/gpio/gpiolib-devres.c > index 5c91c4365da1..7dbce4c4ebdf 100644 > --- a/drivers/gpio/gpiolib-devres.c > +++ b/drivers/gpio/gpiolib-devres.c > @@ -487,10 +487,12 @@ static void devm_gpio_chip_release(struct device *dev, void *res) > } > > /** > - * devm_gpiochip_add_data() - Resource managed gpiochip_add_data() > + * devm_gpiochip_add_data_with_key() - Resource managed gpiochip_add_data_with_key() > * @dev: pointer to the device that gpio_chip belongs to. > * @gc: the GPIO chip to register > * @data: driver-private data associated with this chip > + * @lock_key: lockdep class for IRQ lock > + * @request_key: lockdep class for IRQ request > * > * Context: potentially before irqs will work > * > @@ -501,8 +503,9 @@ static void devm_gpio_chip_release(struct device *dev, void *res) > * gc->base is invalid or already associated with a different chip. > * Otherwise it returns zero as a success code. > */ > -int devm_gpiochip_add_data(struct device *dev, struct gpio_chip *gc, > - void *data) > +int devm_gpiochip_add_data_with_key(struct device *dev, struct gpio_chip *gc, void *data, > + struct lock_class_key *lock_key, > + struct lock_class_key *request_key) > { > struct gpio_chip **ptr; > int ret; > @@ -512,7 +515,7 @@ int devm_gpiochip_add_data(struct device *dev, struct gpio_chip *gc, > if (!ptr) > return -ENOMEM; > > - ret = gpiochip_add_data(gc, data); > + ret = gpiochip_add_data_with_key(gc, data, lock_key, request_key); > if (ret < 0) { > devres_free(ptr); > return ret; > @@ -523,4 +526,4 @@ int devm_gpiochip_add_data(struct device *dev, struct gpio_chip *gc, > > return 0; > } > -EXPORT_SYMBOL_GPL(devm_gpiochip_add_data); > +EXPORT_SYMBOL_GPL(devm_gpiochip_add_data_with_key); > diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h > index c4f272af7af5..e6217d8e2e9f 100644 > --- a/include/linux/gpio/driver.h > +++ b/include/linux/gpio/driver.h > @@ -509,8 +509,16 @@ extern int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data, > gpiochip_add_data_with_key(gc, data, &lock_key, \ > &request_key); \ > }) > +#define devm_gpiochip_add_data(dev, gc, data) ({ \ > + static struct lock_class_key lock_key; \ > + static struct lock_class_key request_key; \ > + devm_gpiochip_add_data_with_key(dev, gc, data, &lock_key, \ > + &request_key); \ > + }) > #else > #define gpiochip_add_data(gc, data) gpiochip_add_data_with_key(gc, data, NULL, NULL) > +#define devm_gpiochip_add_data(dev, gc, data) \ > + devm_gpiochip_add_data_with_key(dev, gc, data, NULL, NULL) > #endif /* CONFIG_LOCKDEP */ > > static inline int gpiochip_add(struct gpio_chip *gc) > @@ -518,8 +526,9 @@ static inline int gpiochip_add(struct gpio_chip *gc) > return gpiochip_add_data(gc, NULL); > } > extern void gpiochip_remove(struct gpio_chip *gc); > -extern int devm_gpiochip_add_data(struct device *dev, struct gpio_chip *gc, > - void *data); > +extern int devm_gpiochip_add_data_with_key(struct device *dev, struct gpio_chip *gc, void *data, > + struct lock_class_key *lock_key, > + struct lock_class_key *request_key); > > extern struct gpio_chip *gpiochip_find(void *data, > int (*match)(struct gpio_chip *gc, void *data)); > -- > 2.27.0 > -- With Best Regards, Andy Shevchenko