From f093c388ef8ceff605f267ae9bc212ad98543ce6 Mon Sep 17 00:00:00 2001 From: Antti Palosaari Date: Tue, 12 Jun 2012 16:25:01 -0300 Subject: [PATCH] [media] dvb_usb_v2: use pointers to properties Use pointers to properties as device and adapter properties are constant. No need to embed and copy those structures. Signed-off-by: Antti Palosaari Signed-off-by: Mauro Carvalho Chehab --- drivers/media/dvb/dvb-usb/dvb_usb.h | 4 +- drivers/media/dvb/dvb-usb/dvb_usb_dvb.c | 64 ++++++++++---------- drivers/media/dvb/dvb-usb/dvb_usb_init.c | 69 +++++++++++----------- drivers/media/dvb/dvb-usb/dvb_usb_remote.c | 6 +- drivers/media/dvb/dvb-usb/dvb_usb_urb.c | 10 ++-- 5 files changed, 75 insertions(+), 78 deletions(-) diff --git a/drivers/media/dvb/dvb-usb/dvb_usb.h b/drivers/media/dvb/dvb-usb/dvb_usb.h index b4438173b25c..a972de6f8486 100644 --- a/drivers/media/dvb/dvb-usb/dvb_usb.h +++ b/drivers/media/dvb/dvb-usb/dvb_usb.h @@ -270,7 +270,7 @@ struct dvb_usb_adapter { #define DVB_USB_ADAP_STATE_DVB 0x001 int state; struct dvb_usb_device *dev; - struct dvb_usb_adapter_properties props; + const struct dvb_usb_adapter_properties *props; struct usb_data_stream stream; u8 id; @@ -316,7 +316,7 @@ struct dvb_usb_adapter { * in size_of_priv of dvb_usb_properties). */ struct dvb_usb_device { - struct dvb_usb_device_properties props; + const struct dvb_usb_device_properties *props; const char *name; const char *rc_map; struct dvb_usb_rc rc; diff --git a/drivers/media/dvb/dvb-usb/dvb_usb_dvb.c b/drivers/media/dvb/dvb-usb/dvb_usb_dvb.c index 11ac592270fe..a0f76eb2b6db 100644 --- a/drivers/media/dvb/dvb-usb/dvb_usb_dvb.c +++ b/drivers/media/dvb/dvb-usb/dvb_usb_dvb.c @@ -41,13 +41,13 @@ int dvb_usbv2_adapter_stream_init(struct dvb_usb_adapter *adap) adap->stream.user_priv = adap; /* resolve USB stream configuration for buffer alloc */ - if (adap->dev->props.get_usb_stream_config) { - ret = adap->dev->props.get_usb_stream_config(NULL, + if (adap->dev->props->get_usb_stream_config) { + ret = adap->dev->props->get_usb_stream_config(NULL, &stream_props); if (ret < 0) return ret; } else { - stream_props = adap->props.stream; + stream_props = adap->props->stream; } /* FIXME: can be removed as set later in anyway */ @@ -80,8 +80,8 @@ static int dvb_usb_ctrl_feed(struct dvb_demux_feed *dvbdmxfeed, int onoff) pr_debug("%s: stop feeding\n", __func__); usb_urb_killv2(&adap->stream); - if (adap->dev->props.streaming_ctrl != NULL) { - ret = adap->dev->props.streaming_ctrl(adap, 0); + if (adap->dev->props->streaming_ctrl != NULL) { + ret = adap->dev->props->streaming_ctrl(adap, 0); if (ret < 0) { pr_err("%s: error while stopping stream\n", KBUILD_MODNAME); @@ -97,10 +97,10 @@ static int dvb_usb_ctrl_feed(struct dvb_demux_feed *dvbdmxfeed, int onoff) adap->pid_filtering ? "yes" : "no", dvbdmxfeed->pid, dvbdmxfeed->pid, dvbdmxfeed->index, onoff ? "on" : "off"); - if (adap->props.caps & DVB_USB_ADAP_HAS_PID_FILTER && + if (adap->props->caps & DVB_USB_ADAP_HAS_PID_FILTER && adap->pid_filtering && - adap->props.pid_filter != NULL) - adap->props.pid_filter(adap, dvbdmxfeed->index, + adap->props->pid_filter != NULL) + adap->props->pid_filter(adap, dvbdmxfeed->index, dvbdmxfeed->pid, onoff); /* start the feed if this was the first feed and there is still a feed @@ -111,8 +111,8 @@ static int dvb_usb_ctrl_feed(struct dvb_demux_feed *dvbdmxfeed, int onoff) unsigned int ts_props; /* resolve TS configuration */ - if (adap->dev->props.get_ts_config) { - ret = adap->dev->props.get_ts_config( + if (adap->dev->props->get_ts_config) { + ret = adap->dev->props->get_ts_config( adap->fe[adap->active_fe], &ts_props); if (ret < 0) @@ -129,14 +129,14 @@ static int dvb_usb_ctrl_feed(struct dvb_demux_feed *dvbdmxfeed, int onoff) adap->stream.complete = dvb_usb_data_complete; /* resolve USB stream configuration */ - if (adap->dev->props.get_usb_stream_config) { - ret = adap->dev->props.get_usb_stream_config( + if (adap->dev->props->get_usb_stream_config) { + ret = adap->dev->props->get_usb_stream_config( adap->fe[adap->active_fe], &stream_props); if (ret < 0) return ret; } else { - stream_props = adap->props.stream; + stream_props = adap->props->stream; } pr_debug("%s: submitting all URBs\n", __func__); @@ -144,11 +144,11 @@ static int dvb_usb_ctrl_feed(struct dvb_demux_feed *dvbdmxfeed, int onoff) usb_urb_submitv2(&adap->stream, &stream_props); pr_debug("%s: controlling pid parser\n", __func__); - if (adap->props.caps & DVB_USB_ADAP_HAS_PID_FILTER && - adap->props.caps & + if (adap->props->caps & DVB_USB_ADAP_HAS_PID_FILTER && + adap->props->caps & DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF && - adap->props.pid_filter_ctrl != NULL) { - ret = adap->props.pid_filter_ctrl(adap, + adap->props->pid_filter_ctrl != NULL) { + ret = adap->props->pid_filter_ctrl(adap, adap->pid_filtering); if (ret < 0) { pr_err("%s: could not handle pid_parser\n", @@ -157,8 +157,8 @@ static int dvb_usb_ctrl_feed(struct dvb_demux_feed *dvbdmxfeed, int onoff) } } pr_debug("%s: start feeding\n", __func__); - if (adap->dev->props.streaming_ctrl != NULL) { - ret = adap->dev->props.streaming_ctrl(adap, 1); + if (adap->dev->props->streaming_ctrl != NULL) { + ret = adap->dev->props->streaming_ctrl(adap, 1); if (ret < 0) { pr_err("%s: error while enabling fifo\n", KBUILD_MODNAME); @@ -190,18 +190,18 @@ static int dvb_usb_stop_feed(struct dvb_demux_feed *dvbdmxfeed) int dvb_usbv2_adapter_dvb_init(struct dvb_usb_adapter *adap) { int ret = dvb_register_adapter(&adap->dvb_adap, adap->dev->name, - adap->dev->props.owner, + adap->dev->props->owner, &adap->dev->udev->dev, - adap->dev->props.adapter_nr); + adap->dev->props->adapter_nr); if (ret < 0) { pr_debug("%s: dvb_register_adapter failed=%d\n", __func__, ret); goto err; } adap->dvb_adap.priv = adap; - adap->dvb_adap.fe_ioctl_override = adap->props.fe_ioctl_override; + adap->dvb_adap.fe_ioctl_override = adap->props->fe_ioctl_override; - if (adap->dev->props.read_mac_address) { - if (adap->dev->props.read_mac_address(adap->dev, + if (adap->dev->props->read_mac_address) { + if (adap->dev->props->read_mac_address(adap->dev, adap->dvb_adap.proposed_mac) == 0) pr_info("%s: MAC address: %pM\n", KBUILD_MODNAME, adap->dvb_adap.proposed_mac); @@ -279,8 +279,8 @@ static int dvb_usb_fe_wakeup(struct dvb_frontend *fe) if (ret < 0) goto err; - if (adap->dev->props.frontend_ctrl) { - ret = adap->dev->props.frontend_ctrl(fe, 1); + if (adap->dev->props->frontend_ctrl) { + ret = adap->dev->props->frontend_ctrl(fe, 1); if (ret < 0) goto err; } @@ -310,8 +310,8 @@ static int dvb_usb_fe_sleep(struct dvb_frontend *fe) goto err; } - if (adap->dev->props.frontend_ctrl) { - ret = adap->dev->props.frontend_ctrl(fe, 0); + if (adap->dev->props->frontend_ctrl) { + ret = adap->dev->props->frontend_ctrl(fe, 0); if (ret < 0) goto err; } @@ -337,8 +337,8 @@ int dvb_usbv2_adapter_frontend_init(struct dvb_usb_adapter *adap) memset(adap->fe, 0, sizeof(adap->fe)); adap->active_fe = -1; - if (adap->dev->props.frontend_attach) { - ret = adap->dev->props.frontend_attach(adap); + if (adap->dev->props->frontend_attach) { + ret = adap->dev->props->frontend_attach(adap); if (ret < 0) { pr_debug("%s: frontend_attach() failed=%d\n", __func__, ret); @@ -350,8 +350,8 @@ int dvb_usbv2_adapter_frontend_init(struct dvb_usb_adapter *adap) goto err; } - if (adap->dev->props.tuner_attach) { - ret = adap->dev->props.tuner_attach(adap); + if (adap->dev->props->tuner_attach) { + ret = adap->dev->props->tuner_attach(adap); if (ret < 0) { pr_debug("%s: tuner_attach() failed=%d\n", __func__, ret); diff --git a/drivers/media/dvb/dvb-usb/dvb_usb_init.c b/drivers/media/dvb/dvb-usb/dvb_usb_init.c index 60011f56cc90..be58b8422a33 100644 --- a/drivers/media/dvb/dvb-usb/dvb_usb_init.c +++ b/drivers/media/dvb/dvb-usb/dvb_usb_init.c @@ -30,14 +30,14 @@ static int dvb_usbv2_download_firmware(struct dvb_usb_device *d) const char *name; /* resolve firmware name */ - name = d->props.firmware; - if (d->props.get_firmware_name) { - ret = d->props.get_firmware_name(d, &name); + name = d->props->firmware; + if (d->props->get_firmware_name) { + ret = d->props->get_firmware_name(d, &name); if (ret < 0) goto err; } - if (!d->props.download_firmware) { + if (!d->props->download_firmware) { ret = -EINVAL; goto err; } @@ -54,7 +54,7 @@ static int dvb_usbv2_download_firmware(struct dvb_usb_device *d) pr_info("%s: downloading firmware from file '%s'\n", KBUILD_MODNAME, name); - ret = d->props.download_firmware(d, fw); + ret = d->props->download_firmware(d, fw); release_firmware(fw); @@ -71,13 +71,13 @@ static int dvb_usbv2_i2c_init(struct dvb_usb_device *d) { int ret; - if (!d->props.i2c_algo) { + if (!d->props->i2c_algo) { ret = 0; goto err; } strlcpy(d->i2c_adap.name, d->name, sizeof(d->i2c_adap.name)); - d->i2c_adap.algo = d->props.i2c_algo; + d->i2c_adap.algo = d->props->i2c_algo; d->i2c_adap.algo_data = NULL; d->i2c_adap.dev.parent = &d->udev->dev; @@ -113,9 +113,9 @@ static int dvb_usbv2_adapter_init(struct dvb_usb_device *d) int ret, i, adapter_count; /* resolve adapter count */ - adapter_count = d->props.num_adapters; - if (d->props.get_adapter_count) { - ret = d->props.get_adapter_count(d); + adapter_count = d->props->num_adapters; + if (d->props->get_adapter_count) { + ret = d->props->get_adapter_count(d); if (ret < 0) goto err; @@ -125,28 +125,26 @@ static int dvb_usbv2_adapter_init(struct dvb_usb_device *d) for (i = 0; i < adapter_count; i++) { adap = &d->adapter[i]; adap->dev = d; - adap->id = i; - - memcpy(&adap->props, &d->props.adapter[i], - sizeof(struct dvb_usb_adapter_properties)); + adap->id = i; + adap->props = &d->props->adapter[i]; /* speed - when running at FULL speed we need a HW PID filter */ if (d->udev->speed == USB_SPEED_FULL && - !(adap->props.caps & DVB_USB_ADAP_HAS_PID_FILTER)) { + !(adap->props->caps & DVB_USB_ADAP_HAS_PID_FILTER)) { pr_err("%s: this USB2.0 device cannot be run on a " \ "USB1.1 port (it lacks a hardware " \ "PID filter)\n", KBUILD_MODNAME); ret = -ENODEV; goto err; } else if ((d->udev->speed == USB_SPEED_FULL && - adap->props.caps & DVB_USB_ADAP_HAS_PID_FILTER) || - (adap->props.caps & DVB_USB_ADAP_NEED_PID_FILTERING)) { + adap->props->caps & DVB_USB_ADAP_HAS_PID_FILTER) || + (adap->props->caps & DVB_USB_ADAP_NEED_PID_FILTERING)) { pr_info("%s: will use the device's hardware PID " \ "filter (table count: %d)\n", KBUILD_MODNAME, - adap->props.pid_filter_count); + adap->props->pid_filter_count); adap->pid_filtering = 1; - adap->max_feed_count = adap->props.pid_filter_count; + adap->max_feed_count = adap->props->pid_filter_count; } else { pr_info("%s: will pass the complete MPEG2 transport " \ "stream to the software demuxer\n", @@ -156,11 +154,11 @@ static int dvb_usbv2_adapter_init(struct dvb_usb_device *d) } if (!adap->pid_filtering && dvb_usb_force_pid_filter_usage && - adap->props.caps & DVB_USB_ADAP_HAS_PID_FILTER) { + adap->props->caps & DVB_USB_ADAP_HAS_PID_FILTER) { pr_info("%s: pid filter enabled by module option\n", KBUILD_MODNAME); adap->pid_filtering = 1; - adap->max_feed_count = adap->props.pid_filter_count; + adap->max_feed_count = adap->props->pid_filter_count; } ret = dvb_usbv2_adapter_stream_init(adap); @@ -229,8 +227,8 @@ static int dvb_usbv2_init(struct dvb_usb_device *d) /* check the capabilities and set appropriate variables */ dvb_usbv2_device_power_ctrl(d, 1); - if (d->props.read_config) { - ret = d->props.read_config(d); + if (d->props->read_config) { + ret = d->props->read_config(d); if (ret < 0) goto err; } @@ -243,8 +241,8 @@ static int dvb_usbv2_init(struct dvb_usb_device *d) if (ret < 0) goto err; - if (d->props.init) { - ret = d->props.init(d); + if (d->props->init) { + ret = d->props->init(d); if (ret < 0) goto err; } @@ -274,8 +272,8 @@ int dvb_usbv2_device_power_ctrl(struct dvb_usb_device *d, int onoff) if (d->powered == 0 || (onoff && d->powered == 1)) { /* when switching from 1 to 0 or from 0 to 1 */ pr_debug("%s: power control=%d\n", __func__, onoff); - if (d->props.power_ctrl) { - ret = d->props.power_ctrl(d, onoff); + if (d->props->power_ctrl) { + ret = d->props->power_ctrl(d, onoff); goto err; } } @@ -304,8 +302,8 @@ static void dvb_usbv2_init_work(struct work_struct *work) pr_debug("%s: work_pid=%d\n", __func__, d->work_pid); - if (d->props.size_of_priv) { - d->priv = kzalloc(d->props.size_of_priv, GFP_KERNEL); + if (d->props->size_of_priv) { + d->priv = kzalloc(d->props->size_of_priv, GFP_KERNEL); if (!d->priv) { pr_err("%s: kzalloc() failed\n", KBUILD_MODNAME); ret = -ENOMEM; @@ -313,8 +311,8 @@ static void dvb_usbv2_init_work(struct work_struct *work) } } - if (d->props.identify_state) { - ret = d->props.identify_state(d); + if (d->props->identify_state) { + ret = d->props->identify_state(d); if (ret == 0) { ; } else if (ret == COLD) { @@ -388,11 +386,10 @@ int dvb_usbv2_probe(struct usb_interface *intf, d->rc_map = driver_info->rc_map; d->udev = interface_to_usbdev(intf); d->intf = intf; - memcpy(&d->props, driver_info->props, - sizeof(struct dvb_usb_device_properties)); + d->props = driver_info->props; if (d->intf->cur_altsetting->desc.bInterfaceNumber != - d->props.bInterfaceNumber) { + d->props->bInterfaceNumber) { ret = -ENODEV; goto err_kfree; } @@ -428,8 +425,8 @@ void dvb_usbv2_disconnect(struct usb_interface *intf) if (d->work_pid != current->pid) cancel_work_sync(&d->probe_work); - if (d->props.disconnect) - d->props.disconnect(d); + if (d->props->disconnect) + d->props->disconnect(d); name = d->name; dvb_usbv2_exit(d); diff --git a/drivers/media/dvb/dvb-usb/dvb_usb_remote.c b/drivers/media/dvb/dvb-usb/dvb_usb_remote.c index 4b7cd0e29bfa..f856ab6648c7 100644 --- a/drivers/media/dvb/dvb-usb/dvb_usb_remote.c +++ b/drivers/media/dvb/dvb-usb/dvb_usb_remote.c @@ -43,10 +43,10 @@ int dvb_usbv2_remote_init(struct dvb_usb_device *d) int ret; struct rc_dev *dev; - if (dvb_usbv2_disable_rc_polling || !d->props.get_rc_config) + if (dvb_usbv2_disable_rc_polling || !d->props->get_rc_config) return 0; - ret = d->props.get_rc_config(d, &d->rc); + ret = d->props->get_rc_config(d, &d->rc); if (ret < 0) goto err; @@ -63,7 +63,7 @@ int dvb_usbv2_remote_init(struct dvb_usb_device *d) dev->input_phys = d->rc_phys; usb_to_input_id(d->udev, &dev->input_id); /* TODO: likely RC-core should took const char * */ - dev->driver_name = (char *) d->props.driver_name; + dev->driver_name = (char *) d->props->driver_name; dev->driver_type = d->rc.driver_type; dev->allowed_protos = d->rc.allowed_protos; dev->change_protocol = d->rc.change_protocol; diff --git a/drivers/media/dvb/dvb-usb/dvb_usb_urb.c b/drivers/media/dvb/dvb-usb/dvb_usb_urb.c index a32722087a0c..75b7ac43810d 100644 --- a/drivers/media/dvb/dvb-usb/dvb_usb_urb.c +++ b/drivers/media/dvb/dvb-usb/dvb_usb_urb.c @@ -16,7 +16,7 @@ int dvb_usbv2_generic_rw(struct dvb_usb_device *d, u8 *wbuf, u16 wlen, u8 *rbuf, if (!d || wbuf == NULL || wlen == 0) return -EINVAL; - if (d->props.generic_bulk_ctrl_endpoint == 0) { + if (d->props->generic_bulk_ctrl_endpoint == 0) { pr_err("%s: endpoint for generic control not specified\n", KBUILD_MODNAME); return -EINVAL; @@ -30,7 +30,7 @@ int dvb_usbv2_generic_rw(struct dvb_usb_device *d, u8 *wbuf, u16 wlen, u8 *rbuf, 32, 1, wbuf, wlen, 0); ret = usb_bulk_msg(d->udev, usb_sndbulkpipe(d->udev, - d->props.generic_bulk_ctrl_endpoint), wbuf, wlen, + d->props->generic_bulk_ctrl_endpoint), wbuf, wlen, &actlen, 2000); if (ret) @@ -45,9 +45,9 @@ int dvb_usbv2_generic_rw(struct dvb_usb_device *d, u8 *wbuf, u16 wlen, u8 *rbuf, msleep(delay_ms); ret = usb_bulk_msg(d->udev, usb_rcvbulkpipe(d->udev, - d->props.generic_bulk_ctrl_endpoint_response ? - d->props.generic_bulk_ctrl_endpoint_response : - d->props.generic_bulk_ctrl_endpoint), + d->props->generic_bulk_ctrl_endpoint_response ? + d->props->generic_bulk_ctrl_endpoint_response : + d->props->generic_bulk_ctrl_endpoint), rbuf, rlen, &actlen, 2000); if (ret) -- 2.39.5