Skip to contentSkip to conversation

usb: gadget: f_hid: don't call cdev_init while cdev in use

bug report Dan Carpenter 2 participants 2 messages Apr 10 – Apr 13 USB

lore
Share & tools
lore
#0 lore raw

Hello Michael Zimmermann,

Commit 81ebd43cc0d6 ("usb: gadget: f_hid: don't call cdev_init while cdev in use") from Mar 27, 2026 (linux-next), leads to the following Smatch static checker warning:

	drivers/usb/gadget/function/f_hid.c:1282 hidg_bind()
	warn: missing error code here? 'cdev_alloc()' failed. 'status' = '0'

drivers/usb/gadget/function/f_hid.c

    1263         if (status)
    1264                 goto fail;
    1265 
    1266         hidg->write_pending = 1;
    1267         hidg->req = NULL;
    1268 
    1269         INIT_WORK(&hidg->work, get_report_workqueue_handler);
    1270         hidg->workqueue = alloc_workqueue("report_work",
    1271                                           WQ_FREEZABLE | WQ_MEM_RECLAIM | WQ_PERCPU,
    1272                                           1);
    1273 
    1274         if (!hidg->workqueue) {
    1275                 status = -ENOMEM;
    1276                 goto fail_free_descs;
    1277         }
    1278 
    1279         /* create char device */
    1280         hidg->cdev = cdev_alloc();
    1281         if (!hidg->cdev)

--> 1282 goto fail_free_all;

status = -ENOMEM;

    1283         hidg->cdev->ops = &f_hidg_fops;
    1284 
    1285         status = cdev_device_add(hidg->cdev, &hidg->dev);
    1286         if (status)
    1287                 goto fail_free_all;
    1288 
    1289         return 0;
    1290 fail_free_all:
    1291         destroy_workqueue(hidg->workqueue);
    1292 fail_free_descs:
    1293         usb_free_all_descriptors(f);
    1294 fail:
    1295         ERROR(f->config->cdev, "hidg_bind FAILED\n");
    1296         if (hidg->req != NULL)
    1297                 free_ep_req(hidg->in_ep, hidg->req);
    1298 
    1299         usb_ep_free_request(c->cdev->gadget->ep0, hidg->get_req);
    1300         hidg->get_req = NULL;
    1301 
    1302         return status;
    1303 }

This email is a free service from the Smatch-CI project [smatch.sf.net].

regards,
dan carpenter

#1 lore raw
Quoted 56 lines · Dan Carpenter

Hello Michael Zimmermann,

Commit 81ebd43cc0d6 ("usb: gadget: f_hid: don't call cdev_init while cdev in use") from Mar 27, 2026 (linux-next), leads to the following Smatch static checker warning:

drivers/usb/gadget/function/f_hid.c:1282 hidg_bind()
warn: missing error code here? 'cdev_alloc()' failed. 'status' = '0'

drivers/usb/gadget/function/f_hid.c

    1263         if (status)
    1264                 goto fail;
    1265
    1266         hidg->write_pending = 1;
    1267         hidg->req = NULL;
    1268
    1269         INIT_WORK(&hidg->work, get_report_workqueue_handler);
    1270         hidg->workqueue = alloc_workqueue("report_work",
    1271                                           WQ_FREEZABLE | WQ_MEM_RECLAIM | WQ_PERCPU,
    1272                                           1);
    1273
    1274         if (!hidg->workqueue) {
    1275                 status = -ENOMEM;
    1276                 goto fail_free_descs;
    1277         }
    1278
    1279         /* create char device */
    1280         hidg->cdev = cdev_alloc();
    1281         if (!hidg->cdev)

--> 1282 goto fail_free_all;

status = -ENOMEM;

    1283         hidg->cdev->ops = &f_hidg_fops;
    1284
    1285         status = cdev_device_add(hidg->cdev, &hidg->dev);
    1286         if (status)
    1287                 goto fail_free_all;
    1288
    1289         return 0;
    1290 fail_free_all:
    1291         destroy_workqueue(hidg->workqueue);
    1292 fail_free_descs:
    1293         usb_free_all_descriptors(f);
    1294 fail:
    1295         ERROR(f->config->cdev, "hidg_bind FAILED\n");
    1296         if (hidg->req != NULL)
    1297                 free_ep_req(hidg->in_ep, hidg->req);
    1298
    1299         usb_ep_free_request(c->cdev->gadget->ep0, hidg->get_req);
    1300         hidg->get_req = NULL;
    1301
    1302         return status;
    1303 }
Quoted 4 lines

This email is a free service from the Smatch-CI project [smatch.sf.net].

regards,
dan carpenter

This was already found and fixed by Ethan Tidmore, but thanks for running the tests.
https://lore.kernel.org/linux-usb/[email protected]/