From 5b8530041358bd1f316ed793cc46b73c038172a7 Mon Sep 17 00:00:00 2001 From: Antti Palosaari Date: Thu, 24 May 2012 21:11:42 -0300 Subject: [PATCH] [media] dvb_usb_v2: implement .get_adapter_count() Callback to resolve adapter count of current device. Old static .num_adapters field can be still used but the new .get_adapter_count() has priority if both offered by the driver. Signed-off-by: Antti Palosaari Signed-off-by: Mauro Carvalho Chehab --- drivers/media/dvb/dvb-usb/dvb_usb.h | 1 + drivers/media/dvb/dvb-usb/dvb_usb_init.c | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/drivers/media/dvb/dvb-usb/dvb_usb.h b/drivers/media/dvb/dvb-usb/dvb_usb.h index dc9d09bce107..a3cc557298b4 100644 --- a/drivers/media/dvb/dvb-usb/dvb_usb.h +++ b/drivers/media/dvb/dvb-usb/dvb_usb.h @@ -271,6 +271,7 @@ struct dvb_usb_device_properties { int size_of_priv; int num_adapters; + int (*get_adapter_count) (struct dvb_usb_device *); struct dvb_usb_adapter_properties adapter[MAX_NO_OF_ADAPTER_PER_DEVICE]; int (*power_ctrl) (struct dvb_usb_device *, int); diff --git a/drivers/media/dvb/dvb-usb/dvb_usb_init.c b/drivers/media/dvb/dvb-usb/dvb_usb_init.c index 3314f36208ff..11d5c96a4600 100644 --- a/drivers/media/dvb/dvb-usb/dvb_usb_init.c +++ b/drivers/media/dvb/dvb-usb/dvb_usb_init.c @@ -34,9 +34,19 @@ MODULE_PARM_DESC(force_pid_filter_usage, "force all dvb-usb-devices to use a" \ static int dvb_usb_adapter_init(struct dvb_usb_device *d) { struct dvb_usb_adapter *adap; - int ret, n, o; + int ret, n, o, adapter_count; - for (n = 0; n < d->props.num_adapters; n++) { + /* resolve adapter count */ + adapter_count = d->props.num_adapters; + if (d->props.get_adapter_count) { + ret = d->props.get_adapter_count(d); + if (ret < 0) + goto err; + + adapter_count = ret; + } + + for (n = 0; n < adapter_count; n++) { adap = &d->adapter[n]; adap->dev = d; adap->id = n; @@ -133,6 +143,9 @@ static int dvb_usb_adapter_init(struct dvb_usb_device *d) } return 0; +err: + pr_debug("%s: failed=%d\n", __func__, ret); + return ret; } static int dvb_usb_adapter_exit(struct dvb_usb_device *d) @@ -297,7 +310,7 @@ EXPORT_SYMBOL(dvb_usbv2_device_init); void dvb_usbv2_device_exit(struct usb_interface *intf) { struct dvb_usb_device *d = usb_get_intfdata(intf); - const char *name; + const char *name = NULL; usb_set_intfdata(intf, NULL); if (d) { -- 2.30.2