linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] of/gpiolib: minor constifying
@ 2021-07-28 14:42 Krzysztof Kozlowski
  2021-07-28 14:42 ` [PATCH 1/3] of: unify of_count_phandle_with_args() arguments with !CONFIG_OF Krzysztof Kozlowski
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Krzysztof Kozlowski @ 2021-07-28 14:42 UTC (permalink / raw)
  To: Linus Walleij, Bartosz Golaszewski, Rob Herring, Frank Rowand,
	linux-gpio, linux-kernel, devicetree
  Cc: Krzysztof Kozlowski

Hi,

Minor constifying of pointer to device_node.  Patches depend on each
other (in order of submission).

Best regards,
Krzysztof


Krzysztof Kozlowski (3):
  of: unify of_count_phandle_with_args() arguments with !CONFIG_OF
  gpiolib: constify passed device_node pointer
  gpiolib: of: constify few local device_node variables

 drivers/gpio/gpiolib-devres.c |  2 +-
 drivers/gpio/gpiolib-of.c     | 16 ++++++++--------
 include/linux/gpio/consumer.h |  8 ++++----
 include/linux/of.h            |  2 +-
 include/linux/of_gpio.h       | 15 ++++++++-------
 5 files changed, 22 insertions(+), 21 deletions(-)

-- 
2.27.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 1/3] of: unify of_count_phandle_with_args() arguments with !CONFIG_OF
  2021-07-28 14:42 [PATCH 0/3] of/gpiolib: minor constifying Krzysztof Kozlowski
@ 2021-07-28 14:42 ` Krzysztof Kozlowski
  2021-07-28 14:42 ` [PATCH 2/3] gpiolib: constify passed device_node pointer Krzysztof Kozlowski
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 8+ messages in thread
From: Krzysztof Kozlowski @ 2021-07-28 14:42 UTC (permalink / raw)
  To: Linus Walleij, Bartosz Golaszewski, Rob Herring, Frank Rowand,
	linux-gpio, linux-kernel, devicetree
  Cc: Krzysztof Kozlowski

Unify the declaration of of_count_phandle_with_args() between enabled
and disabled OF by making constifying pointed device_node.

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
---
 include/linux/of.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/of.h b/include/linux/of.h
index 0e786b60bd5d..6f1c41f109bb 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -896,7 +896,7 @@ static inline int of_parse_phandle_with_fixed_args(const struct device_node *np,
 	return -ENOSYS;
 }
 
-static inline int of_count_phandle_with_args(struct device_node *np,
+static inline int of_count_phandle_with_args(const struct device_node *np,
 					     const char *list_name,
 					     const char *cells_name)
 {
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/3] gpiolib: constify passed device_node pointer
  2021-07-28 14:42 [PATCH 0/3] of/gpiolib: minor constifying Krzysztof Kozlowski
  2021-07-28 14:42 ` [PATCH 1/3] of: unify of_count_phandle_with_args() arguments with !CONFIG_OF Krzysztof Kozlowski
@ 2021-07-28 14:42 ` Krzysztof Kozlowski
  2021-07-28 14:42 ` [PATCH 3/3] gpiolib: of: constify few local device_node variables Krzysztof Kozlowski
  2021-08-02 21:39 ` [PATCH 0/3] of/gpiolib: minor constifying Rob Herring
  3 siblings, 0 replies; 8+ messages in thread
From: Krzysztof Kozlowski @ 2021-07-28 14:42 UTC (permalink / raw)
  To: Linus Walleij, Bartosz Golaszewski, Rob Herring, Frank Rowand,
	linux-gpio, linux-kernel, devicetree
  Cc: Krzysztof Kozlowski

Several gpiolib functions receive pointer to struct device_node which is
later passed to OF functions.  These OF functions accept already pointer
to const, so gpiolib can follow similar approach to indicate they are
not modifying the struct device_node.

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
---
 drivers/gpio/gpiolib-devres.c |  2 +-
 drivers/gpio/gpiolib-of.c     |  8 ++++----
 include/linux/gpio/consumer.h |  8 ++++----
 include/linux/of_gpio.h       | 15 ++++++++-------
 4 files changed, 17 insertions(+), 16 deletions(-)

diff --git a/drivers/gpio/gpiolib-devres.c b/drivers/gpio/gpiolib-devres.c
index 4a517e5dedf0..79da85d17b71 100644
--- a/drivers/gpio/gpiolib-devres.c
+++ b/drivers/gpio/gpiolib-devres.c
@@ -145,7 +145,7 @@ EXPORT_SYMBOL_GPL(devm_gpiod_get_index);
  * In case of error an ERR_PTR() is returned.
  */
 struct gpio_desc *devm_gpiod_get_from_of_node(struct device *dev,
-					      struct device_node *node,
+					      const struct device_node *node,
 					      const char *propname, int index,
 					      enum gpiod_flags dflags,
 					      const char *label)
diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
index bbcc7c073f63..1e5a6f63b2fe 100644
--- a/drivers/gpio/gpiolib-of.c
+++ b/drivers/gpio/gpiolib-of.c
@@ -130,7 +130,7 @@ bool of_gpio_need_valid_mask(const struct gpio_chip *gc)
 	return false;
 }
 
-static void of_gpio_flags_quirks(struct device_node *np,
+static void of_gpio_flags_quirks(const struct device_node *np,
 				 const char *propname,
 				 enum of_gpio_flags *flags,
 				 int index)
@@ -236,7 +236,7 @@ static void of_gpio_flags_quirks(struct device_node *np,
  * value on the error condition. If @flags is not NULL the function also fills
  * in flags for the GPIO.
  */
-static struct gpio_desc *of_get_named_gpiod_flags(struct device_node *np,
+static struct gpio_desc *of_get_named_gpiod_flags(const struct device_node *np,
 		     const char *propname, int index, enum of_gpio_flags *flags)
 {
 	struct of_phandle_args gpiospec;
@@ -275,7 +275,7 @@ static struct gpio_desc *of_get_named_gpiod_flags(struct device_node *np,
 	return desc;
 }
 
-int of_get_named_gpio_flags(struct device_node *np, const char *list_name,
+int of_get_named_gpio_flags(const struct device_node *np, const char *list_name,
 			    int index, enum of_gpio_flags *flags)
 {
 	struct gpio_desc *desc;
@@ -303,7 +303,7 @@ EXPORT_SYMBOL_GPL(of_get_named_gpio_flags);
  *
  * In case of error an ERR_PTR() is returned.
  */
-struct gpio_desc *gpiod_get_from_of_node(struct device_node *node,
+struct gpio_desc *gpiod_get_from_of_node(const struct device_node *node,
 					 const char *propname, int index,
 					 enum gpiod_flags dflags,
 					 const char *label)
diff --git a/include/linux/gpio/consumer.h b/include/linux/gpio/consumer.h
index 566feb56601f..bf945b776555 100644
--- a/include/linux/gpio/consumer.h
+++ b/include/linux/gpio/consumer.h
@@ -609,7 +609,7 @@ struct gpio_desc *devm_fwnode_get_gpiod_from_child(struct device *dev,
 #if IS_ENABLED(CONFIG_GPIOLIB) && IS_ENABLED(CONFIG_OF_GPIO)
 struct device_node;
 
-struct gpio_desc *gpiod_get_from_of_node(struct device_node *node,
+struct gpio_desc *gpiod_get_from_of_node(const struct device_node *node,
 					 const char *propname, int index,
 					 enum gpiod_flags dflags,
 					 const char *label);
@@ -619,7 +619,7 @@ struct gpio_desc *gpiod_get_from_of_node(struct device_node *node,
 struct device_node;
 
 static inline
-struct gpio_desc *gpiod_get_from_of_node(struct device_node *node,
+struct gpio_desc *gpiod_get_from_of_node(const struct device_node *node,
 					 const char *propname, int index,
 					 enum gpiod_flags dflags,
 					 const char *label)
@@ -633,7 +633,7 @@ struct gpio_desc *gpiod_get_from_of_node(struct device_node *node,
 struct device_node;
 
 struct gpio_desc *devm_gpiod_get_from_of_node(struct device *dev,
-					      struct device_node *node,
+					      const struct device_node *node,
 					      const char *propname, int index,
 					      enum gpiod_flags dflags,
 					      const char *label);
@@ -644,7 +644,7 @@ struct device_node;
 
 static inline
 struct gpio_desc *devm_gpiod_get_from_of_node(struct device *dev,
-					      struct device_node *node,
+					      const struct device_node *node,
 					      const char *propname, int index,
 					      enum gpiod_flags dflags,
 					      const char *label)
diff --git a/include/linux/of_gpio.h b/include/linux/of_gpio.h
index f821095218b0..8bf2ea859653 100644
--- a/include/linux/of_gpio.h
+++ b/include/linux/of_gpio.h
@@ -49,7 +49,7 @@ static inline struct of_mm_gpio_chip *to_of_mm_gpio_chip(struct gpio_chip *gc)
 	return container_of(gc, struct of_mm_gpio_chip, gc);
 }
 
-extern int of_get_named_gpio_flags(struct device_node *np,
+extern int of_get_named_gpio_flags(const struct device_node *np,
 		const char *list_name, int index, enum of_gpio_flags *flags);
 
 extern int of_mm_gpiochip_add_data(struct device_node *np,
@@ -67,7 +67,7 @@ extern void of_mm_gpiochip_remove(struct of_mm_gpio_chip *mm_gc);
 #include <linux/errno.h>
 
 /* Drivers may not strictly depend on the GPIO support, so let them link. */
-static inline int of_get_named_gpio_flags(struct device_node *np,
+static inline int of_get_named_gpio_flags(const struct device_node *np,
 		const char *list_name, int index, enum of_gpio_flags *flags)
 {
 	if (flags)
@@ -98,7 +98,8 @@ static inline int of_get_named_gpio_flags(struct device_node *np,
  * The above example defines four GPIOs, two of which are not specified.
  * This function will return '4'
  */
-static inline int of_gpio_named_count(struct device_node *np, const char* propname)
+static inline int of_gpio_named_count(const struct device_node *np,
+				      const char *propname)
 {
 	return of_count_phandle_with_args(np, propname, "#gpio-cells");
 }
@@ -109,12 +110,12 @@ static inline int of_gpio_named_count(struct device_node *np, const char* propna
  *
  * Same as of_gpio_named_count, but hard coded to use the 'gpios' property
  */
-static inline int of_gpio_count(struct device_node *np)
+static inline int of_gpio_count(const struct device_node *np)
 {
 	return of_gpio_named_count(np, "gpios");
 }
 
-static inline int of_get_gpio_flags(struct device_node *np, int index,
+static inline int of_get_gpio_flags(const struct device_node *np, int index,
 		      enum of_gpio_flags *flags)
 {
 	return of_get_named_gpio_flags(np, "gpios", index, flags);
@@ -129,7 +130,7 @@ static inline int of_get_gpio_flags(struct device_node *np, int index,
  * Returns GPIO number to use with Linux generic GPIO API, or one of the errno
  * value on the error condition.
  */
-static inline int of_get_named_gpio(struct device_node *np,
+static inline int of_get_named_gpio(const struct device_node *np,
                                    const char *propname, int index)
 {
 	return of_get_named_gpio_flags(np, propname, index, NULL);
@@ -143,7 +144,7 @@ static inline int of_get_named_gpio(struct device_node *np,
  * Returns GPIO number to use with Linux generic GPIO API, or one of the errno
  * value on the error condition.
  */
-static inline int of_get_gpio(struct device_node *np, int index)
+static inline int of_get_gpio(const struct device_node *np, int index)
 {
 	return of_get_gpio_flags(np, index, NULL);
 }
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 3/3] gpiolib: of: constify few local device_node variables
  2021-07-28 14:42 [PATCH 0/3] of/gpiolib: minor constifying Krzysztof Kozlowski
  2021-07-28 14:42 ` [PATCH 1/3] of: unify of_count_phandle_with_args() arguments with !CONFIG_OF Krzysztof Kozlowski
  2021-07-28 14:42 ` [PATCH 2/3] gpiolib: constify passed device_node pointer Krzysztof Kozlowski
@ 2021-07-28 14:42 ` Krzysztof Kozlowski
  2021-08-11  9:00   ` Linus Walleij
  2021-08-02 21:39 ` [PATCH 0/3] of/gpiolib: minor constifying Rob Herring
  3 siblings, 1 reply; 8+ messages in thread
From: Krzysztof Kozlowski @ 2021-07-28 14:42 UTC (permalink / raw)
  To: Linus Walleij, Bartosz Golaszewski, Rob Herring, Frank Rowand,
	linux-gpio, linux-kernel, devicetree
  Cc: Krzysztof Kozlowski

gpiolib does not modify struct device_node, so few local pointers can
point to a const data.

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
---
 drivers/gpio/gpiolib-of.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
index 1e5a6f63b2fe..0ad288ab6262 100644
--- a/drivers/gpio/gpiolib-of.c
+++ b/drivers/gpio/gpiolib-of.c
@@ -122,7 +122,7 @@ static struct gpio_desc *of_xlate_and_get_gpiod_flags(struct gpio_chip *chip,
 bool of_gpio_need_valid_mask(const struct gpio_chip *gc)
 {
 	int size;
-	struct device_node *np = gc->of_node;
+	const struct device_node *np = gc->of_node;
 
 	size = of_property_count_u32_elems(np,  "gpio-reserved-ranges");
 	if (size > 0 && size % 2 == 0)
@@ -373,7 +373,7 @@ static struct gpio_desc *of_find_spi_gpio(struct device *dev, const char *con_id
 					  enum of_gpio_flags *of_flags)
 {
 	char prop_name[32]; /* 32 is max size of property name */
-	struct device_node *np = dev->of_node;
+	const struct device_node *np = dev->of_node;
 	struct gpio_desc *desc;
 
 	/*
@@ -404,7 +404,7 @@ static struct gpio_desc *of_find_spi_cs_gpio(struct device *dev,
 					     unsigned int idx,
 					     unsigned long *flags)
 {
-	struct device_node *np = dev->of_node;
+	const struct device_node *np = dev->of_node;
 
 	if (!IS_ENABLED(CONFIG_SPI_MASTER))
 		return ERR_PTR(-ENOENT);
@@ -440,7 +440,7 @@ static struct gpio_desc *of_find_regulator_gpio(struct device *dev, const char *
 		"wlf,ldo1ena", /* WM8994 */
 		"wlf,ldo2ena", /* WM8994 */
 	};
-	struct device_node *np = dev->of_node;
+	const struct device_node *np = dev->of_node;
 	struct gpio_desc *desc;
 	int i;
 
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 0/3] of/gpiolib: minor constifying
  2021-07-28 14:42 [PATCH 0/3] of/gpiolib: minor constifying Krzysztof Kozlowski
                   ` (2 preceding siblings ...)
  2021-07-28 14:42 ` [PATCH 3/3] gpiolib: of: constify few local device_node variables Krzysztof Kozlowski
@ 2021-08-02 21:39 ` Rob Herring
  2021-08-05 19:22   ` Bartosz Golaszewski
  3 siblings, 1 reply; 8+ messages in thread
From: Rob Herring @ 2021-08-02 21:39 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Linus Walleij, Bartosz Golaszewski, Frank Rowand, linux-gpio,
	linux-kernel, devicetree

On Wed, Jul 28, 2021 at 04:42:26PM +0200, Krzysztof Kozlowski wrote:
> Hi,
> 
> Minor constifying of pointer to device_node.  Patches depend on each
> other (in order of submission).
> 
> Best regards,
> Krzysztof
> 
> 
> Krzysztof Kozlowski (3):
>   of: unify of_count_phandle_with_args() arguments with !CONFIG_OF
>   gpiolib: constify passed device_node pointer
>   gpiolib: of: constify few local device_node variables

For the series,

Reviewed-by: Rob Herring <robh@kernel.org>

> 
>  drivers/gpio/gpiolib-devres.c |  2 +-
>  drivers/gpio/gpiolib-of.c     | 16 ++++++++--------
>  include/linux/gpio/consumer.h |  8 ++++----
>  include/linux/of.h            |  2 +-
>  include/linux/of_gpio.h       | 15 ++++++++-------
>  5 files changed, 22 insertions(+), 21 deletions(-)
> 
> -- 
> 2.27.0
> 
> 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 0/3] of/gpiolib: minor constifying
  2021-08-02 21:39 ` [PATCH 0/3] of/gpiolib: minor constifying Rob Herring
@ 2021-08-05 19:22   ` Bartosz Golaszewski
  0 siblings, 0 replies; 8+ messages in thread
From: Bartosz Golaszewski @ 2021-08-05 19:22 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Linus Walleij, Rob Herring, Frank Rowand, linux-gpio, LKML,
	linux-devicetree

\\\On Mon, Aug 2, 2021 at 11:39 PM Rob Herring <robh@kernel.org> wrote:
>
> On Wed, Jul 28, 2021 at 04:42:26PM +0200, Krzysztof Kozlowski wrote:
> > Hi,
> >
> > Minor constifying of pointer to device_node.  Patches depend on each
> > other (in order of submission).
> >
> > Best regards,
> > Krzysztof
> >
> >
> > Krzysztof Kozlowski (3):
> >   of: unify of_count_phandle_with_args() arguments with !CONFIG_OF
> >   gpiolib: constify passed device_node pointer
> >   gpiolib: of: constify few local device_node variables
>
> For the series,
>
> Reviewed-by: Rob Herring <robh@kernel.org>
>
> >
> >  drivers/gpio/gpiolib-devres.c |  2 +-
> >  drivers/gpio/gpiolib-of.c     | 16 ++++++++--------
> >  include/linux/gpio/consumer.h |  8 ++++----
> >  include/linux/of.h            |  2 +-
> >  include/linux/of_gpio.h       | 15 ++++++++-------
> >  5 files changed, 22 insertions(+), 21 deletions(-)
> >
> > --
> > 2.27.0
> >
> >

Series applied, thanks!

Bart

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 3/3] gpiolib: of: constify few local device_node variables
  2021-07-28 14:42 ` [PATCH 3/3] gpiolib: of: constify few local device_node variables Krzysztof Kozlowski
@ 2021-08-11  9:00   ` Linus Walleij
  2021-08-11  9:47     ` Krzysztof Kozlowski
  0 siblings, 1 reply; 8+ messages in thread
From: Linus Walleij @ 2021-08-11  9:00 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Bartosz Golaszewski, Rob Herring, Frank Rowand,
	open list:GPIO SUBSYSTEM, linux-kernel,
	open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS

On Wed, Jul 28, 2021 at 4:42 PM Krzysztof Kozlowski
<krzysztof.kozlowski@canonical.com> wrote:

> gpiolib does not modify struct device_node, so few local pointers can
> point to a const data.
>
> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>

LGTM
Acked-by: Linus Walleij <linus.walleij@linaro.org>
I guess this needs to be merged with the other two patches?
I suppose in Rob Herrings DT tree?

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 3/3] gpiolib: of: constify few local device_node variables
  2021-08-11  9:00   ` Linus Walleij
@ 2021-08-11  9:47     ` Krzysztof Kozlowski
  0 siblings, 0 replies; 8+ messages in thread
From: Krzysztof Kozlowski @ 2021-08-11  9:47 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Bartosz Golaszewski, Rob Herring, Frank Rowand,
	open list:GPIO SUBSYSTEM, linux-kernel,
	open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS

On 11/08/2021 11:00, Linus Walleij wrote:
> On Wed, Jul 28, 2021 at 4:42 PM Krzysztof Kozlowski
> <krzysztof.kozlowski@canonical.com> wrote:
> 
>> gpiolib does not modify struct device_node, so few local pointers can
>> point to a const data.
>>
>> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
> 
> LGTM
> Acked-by: Linus Walleij <linus.walleij@linaro.org>
> I guess this needs to be merged with the other two patches?
> I suppose in Rob Herrings DT tree?

Bartosz replied he merged it:
https://lore.kernel.org/lkml/CAMpxmJVtxy-GBWmFLp-tMAOf03Fr7fg8RZ2ndMbvAu_M3qEkHQ@mail.gmail.com/



Best regards,
Krzysztof

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-08-11  9:47 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-28 14:42 [PATCH 0/3] of/gpiolib: minor constifying Krzysztof Kozlowski
2021-07-28 14:42 ` [PATCH 1/3] of: unify of_count_phandle_with_args() arguments with !CONFIG_OF Krzysztof Kozlowski
2021-07-28 14:42 ` [PATCH 2/3] gpiolib: constify passed device_node pointer Krzysztof Kozlowski
2021-07-28 14:42 ` [PATCH 3/3] gpiolib: of: constify few local device_node variables Krzysztof Kozlowski
2021-08-11  9:00   ` Linus Walleij
2021-08-11  9:47     ` Krzysztof Kozlowski
2021-08-02 21:39 ` [PATCH 0/3] of/gpiolib: minor constifying Rob Herring
2021-08-05 19:22   ` Bartosz Golaszewski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).