diff options
author | Mauro Carvalho Chehab <m.chehab@samsung.com> | 2014-07-27 15:27:29 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <m.chehab@samsung.com> | 2014-07-27 15:54:21 -0400 |
commit | 184a82784d50ad82aadc3917a3bdd8314a0e9b9b (patch) | |
tree | c11c9d0e79a710a5e7d5957753d7fb94dac6d10f /drivers/media/usb/cx231xx | |
parent | dcb78ac761488f59ac16c2e76534c567017ef57b (diff) |
[media] cx231xx: use devm_ functions to allocate memory
The initialization is already too complex. Use devm_ functions
to make the code simpler and easier to modify.
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
Diffstat (limited to 'drivers/media/usb/cx231xx')
-rw-r--r-- | drivers/media/usb/cx231xx/cx231xx-cards.c | 43 |
1 files changed, 13 insertions, 30 deletions
diff --git a/drivers/media/usb/cx231xx/cx231xx-cards.c b/drivers/media/usb/cx231xx/cx231xx-cards.c index 38d8510f93c2..cd74310887af 100644 --- a/drivers/media/usb/cx231xx/cx231xx-cards.c +++ b/drivers/media/usb/cx231xx/cx231xx-cards.c | |||
@@ -964,12 +964,6 @@ void cx231xx_release_resources(struct cx231xx *dev) | |||
964 | 964 | ||
965 | /* Mark device as unused */ | 965 | /* Mark device as unused */ |
966 | clear_bit(dev->devno, &cx231xx_devused); | 966 | clear_bit(dev->devno, &cx231xx_devused); |
967 | |||
968 | kfree(dev->video_mode.alt_max_pkt_size); | ||
969 | kfree(dev->vbi_mode.alt_max_pkt_size); | ||
970 | kfree(dev->sliced_cc_mode.alt_max_pkt_size); | ||
971 | kfree(dev->ts1_mode.alt_max_pkt_size); | ||
972 | kfree(dev); | ||
973 | } | 967 | } |
974 | 968 | ||
975 | /* | 969 | /* |
@@ -1158,16 +1152,16 @@ static int cx231xx_usb_probe(struct usb_interface *interface, | |||
1158 | } | 1152 | } |
1159 | } while (test_and_set_bit(nr, &cx231xx_devused)); | 1153 | } while (test_and_set_bit(nr, &cx231xx_devused)); |
1160 | 1154 | ||
1155 | udev = usb_get_dev(interface_to_usbdev(interface)); | ||
1156 | |||
1161 | /* allocate memory for our device state and initialize it */ | 1157 | /* allocate memory for our device state and initialize it */ |
1162 | dev = kzalloc(sizeof(*dev), GFP_KERNEL); | 1158 | dev = devm_kzalloc(&udev->dev, sizeof(*dev), GFP_KERNEL); |
1163 | if (dev == NULL) { | 1159 | if (dev == NULL) { |
1164 | cx231xx_err(DRIVER_NAME ": out of memory!\n"); | 1160 | cx231xx_err(DRIVER_NAME ": out of memory!\n"); |
1165 | clear_bit(nr, &cx231xx_devused); | 1161 | clear_bit(nr, &cx231xx_devused); |
1166 | return -ENOMEM; | 1162 | return -ENOMEM; |
1167 | } | 1163 | } |
1168 | 1164 | ||
1169 | udev = usb_get_dev(interface_to_usbdev(interface)); | ||
1170 | |||
1171 | snprintf(dev->name, 29, "cx231xx #%d", nr); | 1165 | snprintf(dev->name, 29, "cx231xx #%d", nr); |
1172 | dev->devno = nr; | 1166 | dev->devno = nr; |
1173 | dev->model = id->driver_info; | 1167 | dev->model = id->driver_info; |
@@ -1270,9 +1264,8 @@ static int cx231xx_usb_probe(struct usb_interface *interface, | |||
1270 | cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n", | 1264 | cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n", |
1271 | dev->video_mode.end_point_addr, | 1265 | dev->video_mode.end_point_addr, |
1272 | dev->video_mode.num_alt); | 1266 | dev->video_mode.num_alt); |
1273 | dev->video_mode.alt_max_pkt_size = | ||
1274 | kmalloc(32 * dev->video_mode.num_alt, GFP_KERNEL); | ||
1275 | 1267 | ||
1268 | dev->video_mode.alt_max_pkt_size = devm_kmalloc_array(&udev->dev, 32, dev->video_mode.num_alt, GFP_KERNEL); | ||
1276 | if (dev->video_mode.alt_max_pkt_size == NULL) { | 1269 | if (dev->video_mode.alt_max_pkt_size == NULL) { |
1277 | cx231xx_errdev("out of memory!\n"); | 1270 | cx231xx_errdev("out of memory!\n"); |
1278 | retval = -ENOMEM; | 1271 | retval = -ENOMEM; |
@@ -1294,7 +1287,7 @@ static int cx231xx_usb_probe(struct usb_interface *interface, | |||
1294 | if (idx >= dev->max_iad_interface_count) { | 1287 | if (idx >= dev->max_iad_interface_count) { |
1295 | cx231xx_errdev("VBI PCB interface #%d doesn't exist\n", idx); | 1288 | cx231xx_errdev("VBI PCB interface #%d doesn't exist\n", idx); |
1296 | retval = -ENODEV; | 1289 | retval = -ENODEV; |
1297 | goto err_vbi_alt; | 1290 | goto err_video_alt; |
1298 | } | 1291 | } |
1299 | uif = udev->actconfig->interface[idx]; | 1292 | uif = udev->actconfig->interface[idx]; |
1300 | 1293 | ||
@@ -1306,13 +1299,12 @@ static int cx231xx_usb_probe(struct usb_interface *interface, | |||
1306 | cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n", | 1299 | cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n", |
1307 | dev->vbi_mode.end_point_addr, | 1300 | dev->vbi_mode.end_point_addr, |
1308 | dev->vbi_mode.num_alt); | 1301 | dev->vbi_mode.num_alt); |
1309 | dev->vbi_mode.alt_max_pkt_size = | ||
1310 | kmalloc(32 * dev->vbi_mode.num_alt, GFP_KERNEL); | ||
1311 | 1302 | ||
1303 | dev->vbi_mode.alt_max_pkt_size = devm_kmalloc_array(&udev->dev, 32, dev->vbi_mode.num_alt, GFP_KERNEL); | ||
1312 | if (dev->vbi_mode.alt_max_pkt_size == NULL) { | 1304 | if (dev->vbi_mode.alt_max_pkt_size == NULL) { |
1313 | cx231xx_errdev("out of memory!\n"); | 1305 | cx231xx_errdev("out of memory!\n"); |
1314 | retval = -ENOMEM; | 1306 | retval = -ENOMEM; |
1315 | goto err_vbi_alt; | 1307 | goto err_video_alt; |
1316 | } | 1308 | } |
1317 | 1309 | ||
1318 | for (i = 0; i < dev->vbi_mode.num_alt; i++) { | 1310 | for (i = 0; i < dev->vbi_mode.num_alt; i++) { |
@@ -1330,7 +1322,7 @@ static int cx231xx_usb_probe(struct usb_interface *interface, | |||
1330 | if (idx >= dev->max_iad_interface_count) { | 1322 | if (idx >= dev->max_iad_interface_count) { |
1331 | cx231xx_errdev("Sliced CC PCB interface #%d doesn't exist\n", idx); | 1323 | cx231xx_errdev("Sliced CC PCB interface #%d doesn't exist\n", idx); |
1332 | retval = -ENODEV; | 1324 | retval = -ENODEV; |
1333 | goto err_sliced_cc_alt; | 1325 | goto err_video_alt; |
1334 | } | 1326 | } |
1335 | uif = udev->actconfig->interface[idx]; | 1327 | uif = udev->actconfig->interface[idx]; |
1336 | 1328 | ||
@@ -1342,13 +1334,12 @@ static int cx231xx_usb_probe(struct usb_interface *interface, | |||
1342 | cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n", | 1334 | cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n", |
1343 | dev->sliced_cc_mode.end_point_addr, | 1335 | dev->sliced_cc_mode.end_point_addr, |
1344 | dev->sliced_cc_mode.num_alt); | 1336 | dev->sliced_cc_mode.num_alt); |
1345 | dev->sliced_cc_mode.alt_max_pkt_size = | 1337 | dev->sliced_cc_mode.alt_max_pkt_size = devm_kmalloc_array(&udev->dev, 32, dev->sliced_cc_mode.num_alt, GFP_KERNEL); |
1346 | kmalloc(32 * dev->sliced_cc_mode.num_alt, GFP_KERNEL); | ||
1347 | 1338 | ||
1348 | if (dev->sliced_cc_mode.alt_max_pkt_size == NULL) { | 1339 | if (dev->sliced_cc_mode.alt_max_pkt_size == NULL) { |
1349 | cx231xx_errdev("out of memory!\n"); | 1340 | cx231xx_errdev("out of memory!\n"); |
1350 | retval = -ENOMEM; | 1341 | retval = -ENOMEM; |
1351 | goto err_sliced_cc_alt; | 1342 | goto err_video_alt; |
1352 | } | 1343 | } |
1353 | 1344 | ||
1354 | for (i = 0; i < dev->sliced_cc_mode.num_alt; i++) { | 1345 | for (i = 0; i < dev->sliced_cc_mode.num_alt; i++) { |
@@ -1366,7 +1357,7 @@ static int cx231xx_usb_probe(struct usb_interface *interface, | |||
1366 | if (idx >= dev->max_iad_interface_count) { | 1357 | if (idx >= dev->max_iad_interface_count) { |
1367 | cx231xx_errdev("TS1 PCB interface #%d doesn't exist\n", idx); | 1358 | cx231xx_errdev("TS1 PCB interface #%d doesn't exist\n", idx); |
1368 | retval = -ENODEV; | 1359 | retval = -ENODEV; |
1369 | goto err_ts1_alt; | 1360 | goto err_video_alt; |
1370 | } | 1361 | } |
1371 | uif = udev->actconfig->interface[idx]; | 1362 | uif = udev->actconfig->interface[idx]; |
1372 | 1363 | ||
@@ -1378,13 +1369,12 @@ static int cx231xx_usb_probe(struct usb_interface *interface, | |||
1378 | cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n", | 1369 | cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n", |
1379 | dev->ts1_mode.end_point_addr, | 1370 | dev->ts1_mode.end_point_addr, |
1380 | dev->ts1_mode.num_alt); | 1371 | dev->ts1_mode.num_alt); |
1381 | dev->ts1_mode.alt_max_pkt_size = | ||
1382 | kmalloc(32 * dev->ts1_mode.num_alt, GFP_KERNEL); | ||
1383 | 1372 | ||
1373 | dev->ts1_mode.alt_max_pkt_size = devm_kmalloc_array(&udev->dev, 32, dev->ts1_mode.num_alt, GFP_KERNEL); | ||
1384 | if (dev->ts1_mode.alt_max_pkt_size == NULL) { | 1374 | if (dev->ts1_mode.alt_max_pkt_size == NULL) { |
1385 | cx231xx_errdev("out of memory!\n"); | 1375 | cx231xx_errdev("out of memory!\n"); |
1386 | retval = -ENOMEM; | 1376 | retval = -ENOMEM; |
1387 | goto err_ts1_alt; | 1377 | goto err_video_alt; |
1388 | } | 1378 | } |
1389 | 1379 | ||
1390 | for (i = 0; i < dev->ts1_mode.num_alt; i++) { | 1380 | for (i = 0; i < dev->ts1_mode.num_alt; i++) { |
@@ -1411,12 +1401,6 @@ static int cx231xx_usb_probe(struct usb_interface *interface, | |||
1411 | request_modules(dev); | 1401 | request_modules(dev); |
1412 | 1402 | ||
1413 | return 0; | 1403 | return 0; |
1414 | err_ts1_alt: | ||
1415 | kfree(dev->sliced_cc_mode.alt_max_pkt_size); | ||
1416 | err_sliced_cc_alt: | ||
1417 | kfree(dev->vbi_mode.alt_max_pkt_size); | ||
1418 | err_vbi_alt: | ||
1419 | kfree(dev->video_mode.alt_max_pkt_size); | ||
1420 | err_video_alt: | 1404 | err_video_alt: |
1421 | /* cx231xx_uninit_dev: */ | 1405 | /* cx231xx_uninit_dev: */ |
1422 | cx231xx_close_extension(dev); | 1406 | cx231xx_close_extension(dev); |
@@ -1432,7 +1416,6 @@ err_v4l2: | |||
1432 | err_if: | 1416 | err_if: |
1433 | usb_put_dev(udev); | 1417 | usb_put_dev(udev); |
1434 | clear_bit(dev->devno, &cx231xx_devused); | 1418 | clear_bit(dev->devno, &cx231xx_devused); |
1435 | kfree(dev); | ||
1436 | return retval; | 1419 | return retval; |
1437 | } | 1420 | } |
1438 | 1421 | ||