Skip to contentSkip to conversation

usb: phy: phy-generic: No need to call gpiod_direction_output() twice

PATCH Felipe Balbi 2 participants 2 messages Feb 3, 2015 8 messages not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): CAOMZO5A=J7HF+AR8aB2CA+we7knoas-vDtLMbh3gVNvgb1aEAg@mail.gmail.com

A message that is not in the archive (sent off-list or not yet received): CAOMZO5DeyqtjDq0a4_qX2SPbaDZunQbSJimrH23gju1mmdA7vQ@mail.gmail.com

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): CAOMZO5AOevmZLKNSRygeWEGzQp-MLkp8pg8Jr536Y-xXPPTKZw@mail.gmail.com

A message that is not in the archive (sent off-list or not yet received): CAOMZO5AOevmZLKNSRygeWEGzQp-MLkp8pg8Jr536Y-xXPPTKZw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#7 lore raw
Quoted 11 lines · Fabio Estevam

Hi Felipe,

Quoted 3 lines · Felipe Balbi

I like this, very much. Two comments though. We requested the gpio with _optional(), and NULL is a valid gpio_desc, this if (nop->gpiod_reset) is unnecessary. And also, since we don't have anymore the assert

But if the reset-gpios property is not present in the dts, then nop->gpiod_reset is NULL, and it is better not to call 'gpiod_direction_output(nop->gpiod_reset, 1)' in this case, right?

it doesn't make a difference though, right ? gpiod_direction_output(NULL, 1) won't do anything.

/me goes look at code

Man this is messed up. If you follow gpiod_get_optional, you'll end up at gpiod_get_index_optional() which I quote below:

1989 struct gpio_desc *__must_check __gpiod_get_index_optional(struct device *dev,

1990                                                         const char *con_id,
1991                                                         unsigned int index,
1992                                                         enum gpiod_flags flags)

1993 {
1994 struct gpio_desc *desc;
1995
1996 desc = gpiod_get_index(dev, con_id, index, flags);
1997 if (IS_ERR(desc)) {
1998 if (PTR_ERR(desc) == -ENOENT)
1999 return NULL;
2000 }
2001
2002 return desc;
2003 }
2004 EXPORT_SYMBOL_GPL(__gpiod_get_index_optional);

So, if the error code is -ENOENT it returns NULL, that tells me NULL is a valid gpio descriptor. If you follow gpiod_direction_output() however, what you get is:

1072 int gpiod_direction_output(struct gpio_desc *desc, int value) 1073 {
1074 if (!desc || !desc->chip) {
1075 pr_warn("%s: invalid GPIO\n", __func__);
1076 return -EINVAL;
1077 }
1078 if (test_bit(FLAG_ACTIVE_LOW, &desc->flags))
1079 value = !value;
1080 return _gpiod_direction_output_raw(desc, value);
1081 }
1082 EXPORT_SYMBOL_GPL(gpiod_direction_output);

That pr_warn() tells me NULL is *not* a valid gpio descriptor. Linus, is that just something that was missed until now ?

Quoted 3 lines
Quoted 1 line

argument, we should rename nop_reset_set() to nop_reset.

Agreed, will change it in v2.

Thanks

Signature · 1 line
balbi

A message that is not in the archive (sent off-list or not yet received): 20150203205217.GA27736-HgARHv6XitJaoMGHk7MhZQC/[email protected]

#9 lore raw
Quoted 2 lines · Felipe Balbi

it doesn't make a difference though, right ? gpiod_direction_output(NULL, 1) won't do anything.

Yes, I will send a v3 without the NULL check.

gpiod_set_value returns immediately if desc is NULL:

void gpiod_set_value(struct gpio_desc *desc, int value)

{
    if (!desc)
        return;

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html