mbox series

[v1,0/5] iio: treewide: rearrange iio trig get/register

Message ID 20220523164159.11579-1-ddrokosov@sberdevices.ru (mailing list archive)
Headers show
Series iio: treewide: rearrange iio trig get/register | expand

Message

Dmitry Rokosov May 23, 2022, 4:41 p.m. UTC
The following patchset resolves problems with iio_trigger_get() and
iio_trigger_register() call order in the different IIO drivers.

IIO trigger interface function iio_trigger_get() should be called after
iio_trigger_register() (or its devm analogue) strictly, because of
iio_trigger_get() acquires module refcnt based on the trigger->owner
pointer, which is initialized inside iio_trigger_register() to
THIS_MODULE.
If this call order is wrong, the next iio_trigger_put() (from sysfs
callbacks or rmmod) will derefence "default" module refcnt, which is
completely incorrect.

Dmitry Rokosov (5):
  iio:accel:bma180: rearrange iio trigger get and register
  iio:accel:kxcjk-1013: rearrange iio trigger get and register
  iio:accel:mxc4005: rearrange iio trigger get and register
  iio:chemical:ccs811: rearrange iio trigger get and register
  iio:humidity:hts221: rearrange iio trigger get and register

 drivers/iio/accel/bma180.c           | 3 ++-
 drivers/iio/accel/kxcjk-1013.c       | 4 ++--
 drivers/iio/accel/mxc4005.c          | 4 ++--
 drivers/iio/chemical/ccs811.c        | 4 ++--
 drivers/iio/humidity/hts221_buffer.c | 5 ++++-
 5 files changed, 12 insertions(+), 8 deletions(-)

Comments

Andy Shevchenko May 23, 2022, 5:40 p.m. UTC | #1
On Mon, May 23, 2022 at 6:42 PM Dmitry Rokosov <DDRokosov@sberdevices.ru> wrote:
>
> The following patchset resolves problems with iio_trigger_get() and
> iio_trigger_register() call order in the different IIO drivers.
>
> IIO trigger interface function iio_trigger_get() should be called after
> iio_trigger_register() (or its devm analogue) strictly, because of
> iio_trigger_get() acquires module refcnt based on the trigger->owner
> pointer, which is initialized inside iio_trigger_register() to
> THIS_MODULE.
> If this call order is wrong, the next iio_trigger_put() (from sysfs
> callbacks or rmmod) will derefence "default" module refcnt, which is

dereference

> completely incorrect.

Cool set! But it sounds like a set of fixes, can you add a Fixes tag
to each of the patches?
Dmitry Rokosov May 23, 2022, 7:06 p.m. UTC | #2
On Mon, May 23, 2022 at 07:40:27PM +0200, Andy Shevchenko wrote:
Hello Andy,

Thank you for quick feedback.

On Mon, May 23, 2022 at 07:40:27PM +0200, Andy Shevchenko wrote:
> > If this call order is wrong, the next iio_trigger_put() (from sysfs
> > callbacks or rmmod) will derefence "default" module refcnt, which is
> 
> dereference
Ah... good catch.

> > completely incorrect.
> 
> Cool set! But it sounds like a set of fixes, can you add a Fixes tag
> to each of the patches?
Sure, no problem, will provide Fixes tags in the next version.