All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: statically allocated input_dev
       [not found]     ` <d120d5000711150630n538a78e3sd3676a19eb051327@mail.gmail.com>
@ 2007-11-15 14:58       ` Tomas Carnecky
  2007-11-15 15:15         ` Dmitry Torokhov
  0 siblings, 1 reply; 2+ messages in thread
From: Tomas Carnecky @ 2007-11-15 14:58 UTC (permalink / raw)
  To: Dmitry Torokhov; +Cc: linux-kernel

CC: lkml, because that's a question anyone familiar with the driver
subsystem can answer.

Dmitry Torokhov wrote:
> On Nov 15, 2007 9:20 AM, Tomas Carnecky <tom@dbservice.com> wrote:
>> Dmitry Torokhov wrote:
>>> No, sorry. Current object lifetime rules require input devices (as
>>> well as platform devices) to be dynamically allocated.
>>>
>> Interesting, especially the 'platform device' bit, because, from
>> ./drivers/block/floppy.c:
>>
>>    floppy_device[drive].name = floppy_device_name;
>>    floppy_device[drive].id = drive;
>>    floppy_device[drive].dev.release = floppy_device_release;
>>
>>    err = platform_device_register(&floppy_device[drive]);
>>
>> where 'floppy_device' is a static array defined as follows:
>>
>>    static struct platform_device floppy_device[N_DRIVE];
>>
>> So is that code incorrect?
>>
> 
> I would not look at floopy code when searching for examples ;)
> 

Statically allocating platform devices works, I can register those just
fine and I don't see any oops when loading/removing the module. Even
though there are no signs of breakage, should I change my code anyway?

I'm trying to keep the code as simple as possible. The platform device,
platform driver and the input device will live only as long as the
module is loaded. There is nothing else that would rely or depend on my
driver. Any advices you can give? Or is there nothing that I could use
to keep the code simple?

tom

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: statically allocated input_dev
  2007-11-15 14:58       ` statically allocated input_dev Tomas Carnecky
@ 2007-11-15 15:15         ` Dmitry Torokhov
  0 siblings, 0 replies; 2+ messages in thread
From: Dmitry Torokhov @ 2007-11-15 15:15 UTC (permalink / raw)
  To: Tomas Carnecky; +Cc: linux-kernel

On Nov 15, 2007 9:58 AM, Tomas Carnecky <tom@dbservice.com> wrote:
> CC: lkml, because that's a question anyone familiar with the driver
> subsystem can answer.
>
> Dmitry Torokhov wrote:
> > On Nov 15, 2007 9:20 AM, Tomas Carnecky <tom@dbservice.com> wrote:
> >> Dmitry Torokhov wrote:
> >>> No, sorry. Current object lifetime rules require input devices (as
> >>> well as platform devices) to be dynamically allocated.
> >>>
> >> Interesting, especially the 'platform device' bit, because, from
> >> ./drivers/block/floppy.c:
> >>
> >>    floppy_device[drive].name = floppy_device_name;
> >>    floppy_device[drive].id = drive;
> >>    floppy_device[drive].dev.release = floppy_device_release;
> >>
> >>    err = platform_device_register(&floppy_device[drive]);
> >>
> >> where 'floppy_device' is a static array defined as follows:
> >>
> >>    static struct platform_device floppy_device[N_DRIVE];
> >>
> >> So is that code incorrect?
> >>
> >
> > I would not look at floopy code when searching for examples ;)
> >
>
> Statically allocating platform devices works, I can register those just
> fine and I don't see any oops when loading/removing the module.

The oops will not happen when you remove the module but later.
Consider you have a process connected to /dev/input/eventX
corresponding to your input device. Opening evdev node pins in memory
(kref is taken) underlying input_dev which in turn pins parent
platform device. This does not increase your module's reference count
so it still can be unloaded. When you unload the module memory
occupied by tyou module is freed and may be reused for something else.

Now the process that had event device opened decides to close it. This
causes krefs dropped from parent input device and platform device
structures. Cleanup routines will run trying to scrub everything
clean, writing either into freed memory, or, even worse, into memory
now occupied by somethign else. BOOM!

> Even
> though there are no signs of breakage, should I change my code anyway?
>

Yes.

> I'm trying to keep the code as simple as possible. The platform device,
> platform driver and the input device will live only as long as the
> module is loaded. There is nothing else that would rely or depend on my
> driver. Any advices you can give? Or is there nothing that I could use
> to keep the code simple?
>

Make the structures dynamically alloocated and feel safe from any
changes in refcounting between underlying objects.

-- 
Dmitry

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2007-11-15 15:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20071115094309.innulage80owccko@www.neopsis.com>
     [not found] ` <d120d5000711150556r18842b09o2ed5ef3db7abd3d9@mail.gmail.com>
     [not found]   ` <473C5595.3010403@dbservice.com>
     [not found]     ` <d120d5000711150630n538a78e3sd3676a19eb051327@mail.gmail.com>
2007-11-15 14:58       ` statically allocated input_dev Tomas Carnecky
2007-11-15 15:15         ` Dmitry Torokhov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.