MCPcopy Create free account
hub / github.com/F-Stack/f-stack / devclass_add_device

Function devclass_add_device

freebsd/kern/subr_bus.c:1699–1723  ·  view source on GitHub ↗

* @internal * @brief Add a device to a devclass * * A unit number is allocated for the device (using the device's * preferred unit number if any) and the device is registered in the * devclass. This allows the device to be looked up by its unit * number, e.g. by decoding a dev_t minor number. * * @param dc the devclass to add to * @param dev the device to add * * @retval 0 success *

Source from the content-addressed store, hash-verified

1697 * @retval ENOMEM memory allocation failure
1698 */
1699static int
1700devclass_add_device(devclass_t dc, device_t dev)
1701{
1702 int buflen, error;
1703
1704 PDEBUG(("%s in devclass %s", DEVICENAME(dev), DEVCLANAME(dc)));
1705
1706 buflen = snprintf(NULL, 0, "%s%d$", dc->name, INT_MAX);
1707 if (buflen < 0)
1708 return (ENOMEM);
1709 dev->nameunit = malloc(buflen, M_BUS, M_NOWAIT|M_ZERO);
1710 if (!dev->nameunit)
1711 return (ENOMEM);
1712
1713 if ((error = devclass_alloc_unit(dc, dev, &dev->unit)) != 0) {
1714 free(dev->nameunit, M_BUS);
1715 dev->nameunit = NULL;
1716 return (error);
1717 }
1718 dc->devices[dev->unit] = dev;
1719 dev->devclass = dc;
1720 snprintf(dev->nameunit, buflen, "%s%d", dc->name, dev->unit);
1721
1722 return (0);
1723}
1724
1725/**
1726 * @internal

Callers 4

make_deviceFunction · 0.85
device_set_devclassFunction · 0.85
device_set_unitFunction · 0.85
devctl2_ioctlFunction · 0.85

Calls 4

snprintfFunction · 0.85
mallocFunction · 0.85
devclass_alloc_unitFunction · 0.85
freeFunction · 0.70

Tested by

no test coverage detected