[ltp] Re: [Patch 2/3] ibm-acpi: LED Subsystem integration.

Richard Purdie linux-thinkpad@linux-thinkpad.org
Thu, 26 Oct 2006 14:11:24 +0100


On Thu, 2006-10-26 at 14:30 +0200, Stefan Schmidt wrote:
> On Thu, 2006-10-26 at 04:10, Shem Multinymous wrote:
> > >+static struct led_classdev thinklight_led = {
> > >+       .name                   = "thinklight:white",
> > >+       .default_trigger        = "none",
> > >+       .brightness_set         = led_thinklight_set,
> > >+};
> > 
> > Add this to the above macro too.
> > There should be exactly one line per LED in all of the above, with the
> > rest factored out.
> 
> Yes, that sounds good.

There is actually another way you can handle this with much less code
overhead. Have a look at leds-ixp4xx-gpio.c, specifically its use of
container_of(). Basically, you can surround struct led_classdev with
your own data, in this case your led number, then you only need one
brightness_set function.

> Indeed. Even if goto is not the right thing on other problems, it can
> make the code less bloated here.

Init function error handling is the one place goto is valid and actively
encouraged in the kernel :)

Regards,

Richard