Re: [PATCH] gpio: palmas: add dt support

From: Stephen Warren
Date: Tue Apr 02 2013 - 11:31:00 EST


On 04/02/2013 03:01 AM, Linus Walleij wrote:
> On Thu, Mar 28, 2013 at 3:55 PM, Stephen Warren <swarren@xxxxxxxxxx> wrote:
>> On 03/27/2013 11:59 PM, Laxman Dewangan wrote:
>>> On Wednesday 27 March 2013 06:30 PM, Linus Walleij wrote:
>>>> On Thu, Mar 21, 2013 at 3:30 PM, Laxman Dewangan
>>>> <ldewangan@xxxxxxxxxx> wrote:
>>>>
>>>>> +#ifdef CONFIG_OF
>>>>> +static struct of_device_id of_palmas_gpio_match[] = {
>>>>> + { .compatible = "ti,palmas-gpio"},
>>>>> + { },
>>>>> +};
>>>>> +MODULE_DEVICE_TABLE(of, of_palmas_gpio_match);
>>>>> +#endif
>>>>
>>>> But please drop the #ifdef here unless it causes compile errors
>>>> (I don't think it will.)
>>>>
>>>
>>> I am using this table as
>>>
>>> driver.of_match_table = of_match_ptr(of_palmas_gpio_match),
>>> of_match_ptr is macro which is NULL in case of CONFIG_OF not defined.
>>> So if I remove ifdefs then it may create build warning as unused variable.
>>
>> I think Linus's point is that you can simply remove the use of
>> of_match_ptr(). The only disadvantage of doing so is that the table will
>> always be included in the object file, but it's so small that it's
>> probably not worth worrying about.
>
> Oh I wasn't that smart :-)
>
> But what you're saying seems true.
>
> The of_match_ptr() is something
> I haven't quite seen before and don't quite understand the
> semantics of, why would we use that?

Very roughly,

of_match_ptr(x) == CONFIG_OF ? x : NULL

(although with ifdefs rather than the ternary operator)

So, if you have ifdef'd the match table with CONFIG_OF, and reference it
from code outside that ifdef, then you need to use of_match_ptr() to
reference the table, so it isn't referenced when CONFIG_OF is not
defined, and hence never causes link problems.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/