]> git.baikalelectronics.ru Git - kernel.git/commit
media: dvb_frontend: only use kref after initialized
authorMauro Carvalho Chehab <mchehab@s-opensource.com>
Tue, 12 Sep 2017 09:58:26 +0000 (05:58 -0400)
committerMauro Carvalho Chehab <mchehab@s-opensource.com>
Wed, 11 Oct 2017 16:47:36 +0000 (12:47 -0400)
commit83732a6b6a1b3376f11f002e8ee341bc4f63e40f
treeffb5d237da8fe253001f0179a8700925e75a53ef
parent2b088fecebbb35d640882e1ee4c45a96e451155d
media: dvb_frontend: only use kref after initialized

As reported by Laurent, when a DVB frontend need to register
two drivers (e. g. a tuner and a demod), if the second driver
fails to register (for example because it was not compiled),
the error handling logic frees the frontend by calling
dvb_frontend_detach(). That used to work fine, but changeset
f90d92dcac2e ("[media] dvb_frontend: move kref to struct dvb_frontend")
added a kref at struct dvb_frontend. So, now, instead of just
freeing the data, the error handling do a kref_put().

That works fine only after dvb_register_frontend() succeeds.

While it would be possible to add a helper function that
would be initializing earlier the kref, that would require
changing every single DVB frontend on non-trivial ways, and
would make frontends different than other drivers.

So, instead of doing that, let's focus on the real issue:
only call kref_put() after kref_init(). That's easy to
check, as, when the dvb frontend is successfuly registered,
it will allocate its own private struct. So, if such
struct is allocated, it means that it is safe to use
kref_put(). If not, then nobody is using yet the frontend,
and it is safe to just deallocate it.

Fixes: f90d92dcac2e ("[media] dvb_frontend: move kref to struct dvb_frontend")
Reported-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
drivers/media/dvb-core/dvb_frontend.c