Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

media: don't drop front-end reference count for ->detach

A bugfix introduce a link failure in configurations without CONFIG_MODULES:

In file included from drivers/media/usb/dvb-usb/pctv452e.c:20:0:
drivers/media/usb/dvb-usb/pctv452e.c: In function 'pctv452e_frontend_attach':
drivers/media/dvb-frontends/stb0899_drv.h:151:36: error: weak declaration of 'stb0899_attach' being applied to a already existing, static definition

The problem is that the !IS_REACHABLE() declaration of stb0899_attach()
is a 'static inline' definition that clashes with the weak definition.

I further observed that the bugfix was only done for one of the five users
of stb0899_attach(), the other four still have the problem. This reverts
the bugfix and instead addresses the problem by not dropping the reference
count when calling '->detach()', instead we call this function directly
in dvb_frontend_put() before dropping the kref on the front-end.

I first submitted this in early 2018, and after some discussion it
was apparently discarded. While there is a long-term plan in place,
that plan is obviously not nearing completion yet, and the current
kernel is still broken unless this patch is applied.

Link: https://patchwork.kernel.org/patch/10140175/
Link: https://patchwork.linuxtv.org/patch/54831/

Cc: Max Kellermann <max.kellermann@gmail.com>
Cc: Wolfgang Rohdewald <wolfgang@rohdewald.de>
Cc: stable@vger.kernel.org
Fixes: f686c14364ad ("[media] stb0899: move code to "detach" callback")
Fixes: 6cdeaed3b142 ("media: dvb_usb_pctv452e: module refcount changes were unbalanced")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Sean Young <sean@mess.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>

authored by

Arnd Bergmann and committed by
Mauro Carvalho Chehab
14e3cdbb 4590c074

+3 -9
+3 -1
drivers/media/dvb-core/dvb_frontend.c
··· 152 152 153 153 static void dvb_frontend_put(struct dvb_frontend *fe) 154 154 { 155 + /* call detach before dropping the reference count */ 156 + if (fe->ops.detach) 157 + fe->ops.detach(fe); 155 158 /* 156 159 * Check if the frontend was registered, as otherwise 157 160 * kref was not initialized yet. ··· 3043 3040 dvb_frontend_invoke_release(fe, fe->ops.release_sec); 3044 3041 dvb_frontend_invoke_release(fe, fe->ops.tuner_ops.release); 3045 3042 dvb_frontend_invoke_release(fe, fe->ops.analog_ops.release); 3046 - dvb_frontend_invoke_release(fe, fe->ops.detach); 3047 3043 dvb_frontend_put(fe); 3048 3044 } 3049 3045 EXPORT_SYMBOL(dvb_frontend_detach);
-8
drivers/media/usb/dvb-usb/pctv452e.c
··· 909 909 &a->dev->i2c_adap); 910 910 if (!a->fe_adap[0].fe) 911 911 return -ENODEV; 912 - 913 - /* 914 - * dvb_frontend will call dvb_detach for both stb0899_detach 915 - * and stb0899_release but we only do dvb_attach(stb0899_attach). 916 - * Increment the module refcount instead. 917 - */ 918 - symbol_get(stb0899_attach); 919 - 920 912 if ((dvb_attach(lnbp22_attach, a->fe_adap[0].fe, 921 913 &a->dev->i2c_adap)) == NULL) 922 914 err("Cannot attach lnbp22\n");