Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1013561pxj; Fri, 4 Jun 2021 04:05:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx2jnOJwdqjKe3LDUkUHwNcfz8q4/WiEZHfLiaFPEg45bkd1MmN6Vdmz3s0zVat3odOge8X X-Received: by 2002:a05:6402:487:: with SMTP id k7mr3981314edv.315.1622804756697; Fri, 04 Jun 2021 04:05:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622804756; cv=none; d=google.com; s=arc-20160816; b=wYOhFhi1lRONQNyxsmQAiVtHeI7co3caveULKoIIygsogwT6M3Qdtlu3eo7StORY5s kMoNXmZo3kOr8i5EyeiH4s+iv4UXOBXoicYjcaMFl7MGdK+BR1gJxasVS0rtOXi/2HC6 ifxVjmMwkOfSW+qBTO3zxmqjA+x8ZbNEPpy16fvP7E5Z+k3uxDyVuK43OYisVxRIiWiD U7iitPAKSWxYGHF/Lv8TQkXykRCdFKVEarANZnAL+n24o5FRHtDmjxwRW90vaxkUlrtO rMv/LQKRwTkqyArXCFpsd7O/SLhP9jRLDyr/b8YjDps8xFDXTdn4m6So7867s3i5g5zZ gv6g== 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:dkim-signature; bh=5fw8Jf40Gc/YuYU1WK16FbnwfZPGSnpE7hlni55+Ha0=; b=F0K0HFGpx8SqZPwJsgwhMtldeJPV9XAELfpW+PK0fAu33YQMy3E6fRBRc5FnI3d1ja x0PqfSvEBC10Q7aGNig/VgxeEpCGU0XlhuI/HGMIdnm76DLz9xhiIFzhZALmHKzRfBWr 9NHZd+T9fpylso5yJjJWdIAboxaz8Tcadjs2cQGoKNMgU6n2jgVB32lVKPp2vL8xVh61 zynfxks663NnT4lzQke96iVdkjCmY46aNrEfcL1Sv1QGWYG+RzgA6gl3LO51J7OcAThz ZZ2QDRjEzLnkT6/ltfS6R3khuLHrAOWGyALFbtzqMgK9QjKnzFtfyqJAEAh09IcawAQ/ 9Ckg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2016061301 header.b=d+8jCeZ9; 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 i23si4369518ejv.640.2021.06.04.04.05.33; Fri, 04 Jun 2021 04:05:56 -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=@walle.cc header.s=mail2016061301 header.b=d+8jCeZ9; 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 S230010AbhFDLGA (ORCPT + 99 others); Fri, 4 Jun 2021 07:06:00 -0400 Received: from ssl.serverraum.org ([176.9.125.105]:33739 "EHLO ssl.serverraum.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229682AbhFDLF7 (ORCPT ); Fri, 4 Jun 2021 07:05:59 -0400 Received: from mwalle01.fritz.box (ip4d17858c.dynamic.kabel-deutschland.de [77.23.133.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by ssl.serverraum.org (Postfix) with ESMTPSA id 17FAA22236; Fri, 4 Jun 2021 13:04:12 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2016061301; t=1622804652; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=5fw8Jf40Gc/YuYU1WK16FbnwfZPGSnpE7hlni55+Ha0=; b=d+8jCeZ9AwzGcxK23g/UXjvhJSCYFuBvqkzA7UvjyjwboxqckGWyLbpUYsgVU+w5Z8wOEC zhIYxGcpHR4ClJNlxBNKfwlJkQ8vW/exHgl5PsOEofAvCmeDuae3oR9yYRSK4mVFPqte3X kgh7JdVrL3voI7RBuXI/5CtdvQO0LP8= From: Michael Walle To: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Linus Walleij , Bartosz Golaszewski , Michael Walle , Matti Vaittinen Subject: [PATCH] gpio: regmap: move drvdata to config data Date: Fri, 4 Jun 2021 13:04:06 +0200 Message-Id: <20210604110406.11006-1-michael@walle.cc> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Drop gpio_regmap_set_drvdata() and instead add it to the configuration data passed to gpio_regmap_register(). gpio_regmap_set_drvdata() can't really be used in a race free way. This is because the gpio_regmap object which is needed by _set_drvdata() is returned by gpio_regmap_register(). On the other hand, the callbacks which use the drvdata might already be called right after the gpiochip_add() call in gpio_regmap_register(). Therefore, we have to provide the drvdata early before we call gpiochip_add(). Reported-by: Matti Vaittinen Signed-off-by: Michael Walle --- Btw, I'm not sure how to handle this "was part of another patch by another author" thing. Should I leave the Sob and just add mine? I certainly don't want to take credit for work Matti had done. This patch isn't huge, but still ;) drivers/gpio/gpio-regmap.c | 7 +------ include/linux/gpio/regmap.h | 6 +++++- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/drivers/gpio/gpio-regmap.c b/drivers/gpio/gpio-regmap.c index 134cedf151a7..583cd1cdead8 100644 --- a/drivers/gpio/gpio-regmap.c +++ b/drivers/gpio/gpio-regmap.c @@ -178,12 +178,6 @@ static int gpio_regmap_direction_output(struct gpio_chip *chip, return gpio_regmap_set_direction(chip, offset, true); } -void gpio_regmap_set_drvdata(struct gpio_regmap *gpio, void *data) -{ - gpio->driver_data = data; -} -EXPORT_SYMBOL_GPL(gpio_regmap_set_drvdata); - void *gpio_regmap_get_drvdata(struct gpio_regmap *gpio) { return gpio->driver_data; @@ -226,6 +220,7 @@ struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config return ERR_PTR(-ENOMEM); gpio->parent = config->parent; + gpio->driver_data = config->drvdata; gpio->regmap = config->regmap; gpio->ngpio_per_reg = config->ngpio_per_reg; gpio->reg_stride = config->reg_stride; diff --git a/include/linux/gpio/regmap.h b/include/linux/gpio/regmap.h index 334dd928042b..a9f7b7faf57b 100644 --- a/include/linux/gpio/regmap.h +++ b/include/linux/gpio/regmap.h @@ -37,6 +37,9 @@ struct regmap; * offset to a register/bitmask pair. If not * given the default gpio_regmap_simple_xlate() * is used. + * @drvdata: (Optional) Pointer to driver specific data which is + * not used by gpio-remap but is provided "as is" to the + * driver callback(s). * * The ->reg_mask_xlate translates a given base address and GPIO offset to * register and mask pair. The base address is one of the given register @@ -78,13 +81,14 @@ struct gpio_regmap_config { int (*reg_mask_xlate)(struct gpio_regmap *gpio, unsigned int base, unsigned int offset, unsigned int *reg, unsigned int *mask); + + void *drvdata; }; struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config); void gpio_regmap_unregister(struct gpio_regmap *gpio); struct gpio_regmap *devm_gpio_regmap_register(struct device *dev, const struct gpio_regmap_config *config); -void gpio_regmap_set_drvdata(struct gpio_regmap *gpio, void *data); void *gpio_regmap_get_drvdata(struct gpio_regmap *gpio); #endif /* _LINUX_GPIO_REGMAP_H */ -- 2.20.1