2004-06-01 21:24:34

by Jeff Garzik

[permalink] [raw]
Subject: Re: two patches - request for comments

Andrew Zabolotny wrote:
> No. class_find_device was written for lcd_find_device() and
> backlight_find_device() (framebuffer devices use them). On the other hand,
> the driver that registers the backlight device doesn't have a pointer to the
> class device (well, the lcd_register_device could return it). Since the
> lcd/backlight names are unique anyway, I don't see any problems with that, and
> moreover, it is *registered* by giving it a name, why it should be
> unregistered in a different way?


Typical Linux usage to an item being registered is

ptr = alloc_foo()
register_foo(ptr)
unregister_foo(ptr)
free_foo()

It is quite unusual to unregister based on name. Pointers are far more
likely to be unique, and the programmer is far less likely to screw up
the unregister operation.

Jeff



2004-06-01 21:58:00

by Andrew Zabolotny

[permalink] [raw]
Subject: Re: two patches - request for comments

On Tue, 01 Jun 2004 17:23:11 -0400
Jeff Garzik <[email protected]> wrote:

> Typical Linux usage to an item being registered is
> ptr = alloc_foo()
> register_foo(ptr)
> unregister_foo(ptr)
> free_foo()
In this case it is:

register_lcd_device("foo", ...);
...
unregister_lcd_device("foo");

The name is guaranteed to be unique by sysfs design during the whole
device lifetime, and calling unregister_xxx() outside the lifetime brackets
is clearly an error.

> It is quite unusual to unregister based on name. Pointers are far more
> likely to be unique, and the programmer is far less likely to screw up
> the unregister operation.
I understand this, I see why it looks unusual. I'll fix this if it matters.
It'll be something like:

lcd_device = register_lcd_device ("foo", ...);
...
unregister_lcd_device (lcd_device);

However, this extra pointer will take some memory; not much of course.

--
Greetings,
Andrew

2004-06-02 17:35:44

by Greg KH

[permalink] [raw]
Subject: Re: two patches - request for comments

On Wed, Jun 02, 2004 at 01:57:40AM +0400, Andrew Zabolotny wrote:
> On Tue, 01 Jun 2004 17:23:11 -0400
> Jeff Garzik <[email protected]> wrote:
>
> > Typical Linux usage to an item being registered is
> > ptr = alloc_foo()
> > register_foo(ptr)
> > unregister_foo(ptr)
> > free_foo()
> In this case it is:
>
> register_lcd_device("foo", ...);
> ...
> unregister_lcd_device("foo");
>
> The name is guaranteed to be unique by sysfs design during the whole
> device lifetime, and calling unregister_xxx() outside the lifetime brackets
> is clearly an error.
>
> > It is quite unusual to unregister based on name. Pointers are far more
> > likely to be unique, and the programmer is far less likely to screw up
> > the unregister operation.
> I understand this, I see why it looks unusual. I'll fix this if it matters.

It matters, please fix it.

> It'll be something like:
>
> lcd_device = register_lcd_device ("foo", ...);
> ...
> unregister_lcd_device (lcd_device);

What about:
lcd_device = alloc_lcd_device("foo", ...);
error = register_lcd_device(lcd_device);
...
unregister_lcd_device(lcd_device);

thanks,

greg k-h