On Tue, Jul 7, 2020 at 5:09 PM mnlife <mnlife@xxxxxxxxxxx> wrote: > > when I get gpiod optional failed, I am confused for a long time. > finally I find out that because of the string con_id is too long, > prop_name is truncated. > > Signed-off-by: mnlife <mnlife@xxxxxxxxxxx> > --- > drivers/gpio/gpiolib-of.c | 13 +++++++++---- > 1 file changed, 9 insertions(+), 4 deletions(-) > > diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c > index ccc449df3792..11740f292420 100644 > --- a/drivers/gpio/gpiolib-of.c > +++ b/drivers/gpio/gpiolib-of.c > @@ -467,15 +467,20 @@ struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id, > enum of_gpio_flags of_flags; > struct gpio_desc *desc; > unsigned int i; > + int size; > > /* Try GPIO property "foo-gpios" and "foo-gpio" */ > for (i = 0; i < ARRAY_SIZE(gpio_suffixes); i++) { > if (con_id) > - snprintf(prop_name, sizeof(prop_name), "%s-%s", con_id, > - gpio_suffixes[i]); > + size = snprintf(prop_name, sizeof(prop_name), "%s-%s", > + con_id, gpio_suffixes[i]); > else > - snprintf(prop_name, sizeof(prop_name), "%s", > - gpio_suffixes[i]); > + size = snprintf(prop_name, sizeof(prop_name), "%s", > + gpio_suffixes[i]); > + > + if (size >= sizeof(prop_name)) > + dev_warn(dev, "prop_name %s is truncated with size %d\n", > + prop_name, size); > > desc = of_get_named_gpiod_flags(dev->of_node, prop_name, idx, > &of_flags); > -- > 2.17.1 > To me this isn't a reason for a warning. If anything, this should simply be documented (if it's not already). Bart