Use the recently added "make_dev_s()" function to solve old race setting the
si_drv1 field in "struct cdev" when creating new character devices.
This commit is contained in:
parent
ed5c72c308
commit
ac3490fdef
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=294088
@ -1962,6 +1962,7 @@ usb_make_dev(struct usb_device *udev, const char *devname, int ep,
|
||||
int fi, int rwmode, uid_t uid, gid_t gid, int mode)
|
||||
{
|
||||
struct usb_fs_privdata* pd;
|
||||
struct make_dev_args args;
|
||||
char buffer[32];
|
||||
|
||||
/* Store information to locate ourselves again later */
|
||||
@ -1980,17 +1981,19 @@ usb_make_dev(struct usb_device *udev, const char *devname, int ep,
|
||||
pd->bus_index, pd->dev_index, pd->ep_addr);
|
||||
}
|
||||
|
||||
pd->cdev = make_dev(&usb_devsw, 0, uid, gid, mode, "%s", devname);
|
||||
/* Setup arguments for make_dev_s() */
|
||||
make_dev_args_init(&args);
|
||||
args.mda_devsw = &usb_devsw;
|
||||
args.mda_uid = uid;
|
||||
args.mda_gid = gid;
|
||||
args.mda_mode = mode;
|
||||
args.mda_si_drv1 = pd;
|
||||
|
||||
if (pd->cdev == NULL) {
|
||||
if (make_dev_s(&args, &pd->cdev, "%s", devname) != 0) {
|
||||
DPRINTFN(0, "Failed to create device %s\n", devname);
|
||||
free(pd, M_USBDEV);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
/* XXX setting si_drv1 and creating the device is not atomic! */
|
||||
pd->cdev->si_drv1 = pd;
|
||||
|
||||
return (pd);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user