hc
2024-01-03 2f7c68cb55ecb7331f2381deb497c27155f32faf
kernel/drivers/media/usb/dvb-usb/dvb-usb-init.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * DVB USB library - provides a generic interface for a DVB USB device driver.
34 *
....@@ -5,11 +6,7 @@
56 *
67 * Copyright (C) 2004-6 Patrick Boettcher (patrick.boettcher@posteo.de)
78 *
8
- * This program is free software; you can redistribute it and/or modify it
9
- * under the terms of the GNU General Public License as published by the Free
10
- * Software Foundation, version 2.
11
- *
12
- * see Documentation/media/dvb-drivers/dvb-usb.rst for more information
9
+ * see Documentation/driver-api/media/drivers/dvb-usb.rst for more information
1310 */
1411 #include "dvb-usb-common.h"
1512
....@@ -84,7 +81,7 @@
8481
8582 ret = dvb_usb_adapter_stream_init(adap);
8683 if (ret)
87
- return ret;
84
+ goto stream_init_err;
8885
8986 ret = dvb_usb_adapter_dvb_init(adap, adapter_nrs);
9087 if (ret)
....@@ -104,7 +101,7 @@
104101
105102 /*
106103 * when reloading the driver w/o replugging the device
107
- * sometimes a timeout occures, this helps
104
+ * sometimes a timeout occurs, this helps
108105 */
109106 if (d->props.generic_bulk_ctrl_endpoint != 0) {
110107 usb_clear_halt(d->udev, usb_sndbulkpipe(d->udev, d->props.generic_bulk_ctrl_endpoint));
....@@ -117,6 +114,8 @@
117114 dvb_usb_adapter_dvb_exit(adap);
118115 dvb_init_err:
119116 dvb_usb_adapter_stream_exit(adap);
117
+stream_init_err:
118
+ kfree(adap->priv);
120119 return ret;
121120 }
122121
....@@ -145,6 +144,10 @@
145144 dvb_usb_i2c_exit(d);
146145 deb_info("state should be zero now: %x\n", d->state);
147146 d->state = DVB_USB_STATE_INIT;
147
+
148
+ if (d->priv != NULL && d->props.priv_destroy != NULL)
149
+ d->props.priv_destroy(d);
150
+
148151 kfree(d->priv);
149152 kfree(d);
150153 return 0;
....@@ -166,16 +169,23 @@
166169 err("no memory for priv in 'struct dvb_usb_device'");
167170 return -ENOMEM;
168171 }
172
+
173
+ if (d->props.priv_init != NULL) {
174
+ ret = d->props.priv_init(d);
175
+ if (ret != 0)
176
+ goto err_priv_init;
177
+ }
169178 }
170179
171180 /* check the capabilities and set appropriate variables */
172181 dvb_usb_device_power_ctrl(d, 1);
173182
174
- if ((ret = dvb_usb_i2c_init(d)) ||
175
- (ret = dvb_usb_adapter_init(d, adapter_nums))) {
176
- dvb_usb_exit(d);
177
- return ret;
178
- }
183
+ ret = dvb_usb_i2c_init(d);
184
+ if (ret)
185
+ goto err_i2c_init;
186
+ ret = dvb_usb_adapter_init(d, adapter_nums);
187
+ if (ret)
188
+ goto err_adapter_init;
179189
180190 if ((ret = dvb_usb_remote_init(d)))
181191 err("could not initialize remote control.");
....@@ -183,13 +193,24 @@
183193 dvb_usb_device_power_ctrl(d, 0);
184194
185195 return 0;
196
+
197
+err_adapter_init:
198
+ dvb_usb_adapter_exit(d);
199
+ dvb_usb_i2c_exit(d);
200
+err_i2c_init:
201
+ if (d->priv && d->props.priv_destroy)
202
+ d->props.priv_destroy(d);
203
+err_priv_init:
204
+ kfree(d->priv);
205
+ d->priv = NULL;
206
+ return ret;
186207 }
187208
188209 /* determine the name and the state of the just found USB device */
189
-static struct dvb_usb_device_description *dvb_usb_find_device(struct usb_device *udev, struct dvb_usb_device_properties *props, int *cold)
210
+static const struct dvb_usb_device_description *dvb_usb_find_device(struct usb_device *udev, const struct dvb_usb_device_properties *props, int *cold)
190211 {
191212 int i, j;
192
- struct dvb_usb_device_description *desc = NULL;
213
+ const struct dvb_usb_device_description *desc = NULL;
193214
194215 *cold = -1;
195216
....@@ -244,54 +265,63 @@
244265 * USB
245266 */
246267 int dvb_usb_device_init(struct usb_interface *intf,
247
- struct dvb_usb_device_properties *props,
268
+ const struct dvb_usb_device_properties *props,
248269 struct module *owner, struct dvb_usb_device **du,
249270 short *adapter_nums)
250271 {
251272 struct usb_device *udev = interface_to_usbdev(intf);
252273 struct dvb_usb_device *d = NULL;
253
- struct dvb_usb_device_description *desc = NULL;
274
+ const struct dvb_usb_device_description *desc = NULL;
254275
255276 int ret = -ENOMEM, cold = 0;
256277
257278 if (du != NULL)
258279 *du = NULL;
259280
260
- if ((desc = dvb_usb_find_device(udev, props, &cold)) == NULL) {
281
+ d = kzalloc(sizeof(*d), GFP_KERNEL);
282
+ if (!d) {
283
+ err("no memory for 'struct dvb_usb_device'");
284
+ return -ENOMEM;
285
+ }
286
+
287
+ memcpy(&d->props, props, sizeof(struct dvb_usb_device_properties));
288
+
289
+ desc = dvb_usb_find_device(udev, &d->props, &cold);
290
+ if (!desc) {
261291 deb_err("something went very wrong, device was not found in current device list - let's see what comes next.\n");
262
- return -ENODEV;
292
+ ret = -ENODEV;
293
+ goto error;
263294 }
264295
265296 if (cold) {
266297 info("found a '%s' in cold state, will try to load a firmware", desc->name);
267298 ret = dvb_usb_download_firmware(udev, props);
268299 if (!props->no_reconnect || ret != 0)
269
- return ret;
300
+ goto error;
270301 }
271302
272303 info("found a '%s' in warm state.", desc->name);
273
- d = kzalloc(sizeof(struct dvb_usb_device), GFP_KERNEL);
274
- if (d == NULL) {
275
- err("no memory for 'struct dvb_usb_device'");
276
- return -ENOMEM;
277
- }
278
-
279304 d->udev = udev;
280
- memcpy(&d->props, props, sizeof(struct dvb_usb_device_properties));
281305 d->desc = desc;
282306 d->owner = owner;
283307
284308 usb_set_intfdata(intf, d);
285309
286
- if (du != NULL)
310
+ ret = dvb_usb_init(d, adapter_nums);
311
+ if (ret) {
312
+ info("%s error while loading driver (%d)", desc->name, ret);
313
+ goto error;
314
+ }
315
+
316
+ if (du)
287317 *du = d;
288318
289
- ret = dvb_usb_init(d, adapter_nums);
319
+ info("%s successfully initialized and connected.", desc->name);
320
+ return 0;
290321
291
- if (ret == 0)
292
- info("%s successfully initialized and connected.", desc->name);
293
- else
294
- info("%s error while loading driver (%d)", desc->name, ret);
322
+ error:
323
+ usb_set_intfdata(intf, NULL);
324
+ kfree(d);
295325 return ret;
296326 }
297327 EXPORT_SYMBOL(dvb_usb_device_init);