// /ont void l2_drv_dbg_sysfs_init(void) { int ret; printk(KERN_INFO "Create ONT in sysfs\r\n"); OntKset.kobj.ktype = &OntKobjType; kobject_set_name(&OntKset.kobj, "ont"); OntKset.kobj.kset = NULL; ret = kset_register(&OntKset); if (ret) { return ; } kobject_set_name(&l2dKset.kobj, "l2d"); l2dKset.kobj.kset = &OntKset; l2dKset.kobj.ktype= &l2dKobjType; ret = kset_register(&l2dKset); if (ret) { return ; } l2_drv_dbg_l2d_init(&l2dKset); l2_drv_igmp_kobj_init(&l2dKset); }
/** * bus_register - register a bus with the system. * @bus: bus. * * Once we have that, we registered the bus with the kobject * infrastructure, then register the children subsystems it has: * the devices and drivers that belong to the bus. */ int bus_register(struct bus_type * bus) { int retval = -ENOMEM; struct blocking_notifier_head *notifier_head; notifier_head = alloc_save_notifier_for_bus(bus); if (!notifier_head) goto out; BLOCKING_INIT_NOTIFIER_HEAD(notifier_head); retval = kobject_set_name(&bus->subsys.kset.kobj, "%s", bus->name); if (retval) goto out; subsys_set_kset(bus, bus_subsys); retval = subsystem_register(&bus->subsys); if (retval) goto out; kobject_set_name(&bus->devices.kobj, "devices"); bus->devices.subsys = &bus->subsys; retval = kset_register(&bus->devices); if (retval) goto bus_devices_fail; kobject_set_name(&bus->drivers.kobj, "drivers"); bus->drivers.subsys = &bus->subsys; bus->drivers.ktype = &ktype_driver; retval = kset_register(&bus->drivers); if (retval) goto bus_drivers_fail; klist_init(&bus->klist_devices, klist_devices_get, klist_devices_put); klist_init(&bus->klist_drivers, klist_drivers_get, klist_drivers_put); retval = add_probe_files(bus); if (retval) goto bus_probe_files_fail; bus_add_attrs(bus); pr_debug("bus type '%s' registered\n", bus->name); return 0; bus_probe_files_fail: kset_unregister(&bus->drivers); bus_drivers_fail: kset_unregister(&bus->devices); bus_devices_fail: subsystem_unregister(&bus->subsys); out: return retval; }
int kset_test_init(void) { printk("kset test init:\n"); kobject_set_name(&kset_p.kobj, "kset_P"); kset_p.uevent_ops = &uevent_ops; kset_register(&kset_p); kobject_set_name(&kset_c.kobj, "kset_c"); kset_c.kobj.kset = &kset_p; kset_register(&kset_c); return 0; }
/** * bus_add_driver - Add a driver to the bus. * @drv: driver. * */ int bus_add_driver(struct device_driver * drv) { struct bus_type * bus = get_bus(drv->bus); int error = 0; if (bus) { pr_debug("bus %s: add driver %s\n", bus->name, drv->name); error = kobject_set_name(&drv->kobj, "%s", drv->name); if (error) { put_bus(bus); return error; } drv->kobj.kset = &bus->drivers; if ((error = kobject_register(&drv->kobj))) { put_bus(bus); return error; } driver_attach(drv); klist_add_tail(&drv->knode_bus, &bus->klist_drivers); module_add_driver(drv->owner, drv); driver_add_attrs(bus, drv); add_bind_files(drv); } return error; }
/* Initialize the main sysfs entries for edac: * /sys/devices/system/edac * * and children * * Return: 0 SUCCESS * !0 FAILURE */ static int edac_sysfs_memctrl_setup(void) { int err=0; debugf1("%s()\n", __func__); /* create the /sys/devices/system/edac directory */ err = sysdev_class_register(&edac_class); if (!err) { /* Init the MC's kobject */ memset(&edac_memctrl_kobj, 0, sizeof (edac_memctrl_kobj)); edac_memctrl_kobj.parent = &edac_class.kset.kobj; edac_memctrl_kobj.ktype = &ktype_memctrl; /* generate sysfs "..../edac/mc" */ err = kobject_set_name(&edac_memctrl_kobj,"mc"); if (!err) { /* FIXME: maybe new sysdev_create_subdir() */ err = kobject_register(&edac_memctrl_kobj); if (err) debugf1("Failed to register '.../edac/mc'\n"); else debugf1("Registered '.../edac/mc' kobject\n"); } } else debugf1("%s() error=%d\n", __func__, err); return err; }
static int uio_major_init(void) { static const char name[] = "uio"; struct cdev *cdev = NULL; dev_t uio_dev = 0; int result; result = alloc_chrdev_region(&uio_dev, 0, UIO_MAX_DEVICES, name); if (result) goto out; result = -ENOMEM; cdev = cdev_alloc(); if (!cdev) goto out_unregister; cdev->owner = THIS_MODULE; cdev->ops = &uio_fops; kobject_set_name(&cdev->kobj, "%s", name); result = cdev_add(cdev, uio_dev, UIO_MAX_DEVICES); if (result) goto out_put; uio_major = MAJOR(uio_dev); uio_cdev = cdev; return 0; out_put: kobject_put(&cdev->kobj); out_unregister: unregister_chrdev_region(uio_dev, UIO_MAX_DEVICES); out: return result; }
int rfs_sysfs_create(void) { int rv; rfs_kobj = kzalloc(sizeof(struct kobject), GFP_KERNEL); if (!rfs_kobj) return -ENOMEM; kobject_init(rfs_kobj); rfs_kobj->ktype = &rfs_kobj_ktype; rfs_kobj->parent = &fs_subsys.kobj; rv = kobject_set_name(rfs_kobj, "%s", "redirfs"); if (rv) { kobject_put(rfs_kobj); return rv; } rv = kobject_register(rfs_kobj); if (rv) { kobject_put(rfs_kobj); return rv; } rv = -ENOMEM; rfs_flt_kset = kzalloc(sizeof(struct kset), GFP_KERNEL); if (!rfs_flt_kset) goto err_kobj; kobject_init(&rfs_flt_kset->kobj); rfs_flt_kset->kobj.ktype = &rfs_kobj_ktype; rfs_flt_kset->kobj.parent = rfs_kobj; rv = kobject_set_name(&rfs_flt_kset->kobj, "%s", "filters"); if (rv) goto err_kset; rv = kset_register(rfs_flt_kset); if (rv) goto err_kset; return 0; err_kset: kset_put(rfs_flt_kset); err_kobj: kobject_unregister(rfs_kobj); return rv; }
/** * bus_register - register a bus with the system. * @bus: bus. * * Once we have that, we registered the bus with the kobject * infrastructure, then register the children subsystems it has: * the devices and drivers that belong to the bus. */ int bus_register(struct bus_type * bus) { int retval; BLOCKING_INIT_NOTIFIER_HEAD(&bus->bus_notifier); retval = kobject_set_name(&bus->subsys.kset.kobj, "%s", bus->name); if (retval) goto out; subsys_set_kset(bus, bus_subsys); retval = subsystem_register(&bus->subsys); if (retval) goto out; kobject_set_name(&bus->devices.kobj, "devices"); bus->devices.subsys = &bus->subsys; retval = kset_register(&bus->devices); if (retval) goto bus_devices_fail; kobject_set_name(&bus->drivers.kobj, "drivers"); bus->drivers.subsys = &bus->subsys; bus->drivers.ktype = &ktype_driver; retval = kset_register(&bus->drivers); if (retval) goto bus_drivers_fail; klist_init(&bus->klist_devices, klist_devices_get, klist_devices_put); klist_init(&bus->klist_drivers, NULL, NULL); retval = bus_add_attrs(bus); if (retval) goto bus_attrs_fail; pr_debug("bus type '%s' registered\n", bus->name); return 0; bus_attrs_fail: kset_unregister(&bus->drivers); bus_drivers_fail: kset_unregister(&bus->devices); bus_devices_fail: subsystem_unregister(&bus->subsys); out: return retval; }
/** * bus_add_driver - Add a driver to the bus. * @drv: driver. * */ int bus_add_driver(struct device_driver *drv) { struct bus_type * bus = bus_get(drv->bus); int error = 0; if (!bus) return -EINVAL; pr_debug("bus %s: add driver %s\n", bus->name, drv->name); error = kobject_set_name(&drv->kobj, "%s", drv->name); if (error) goto out_put_bus; drv->kobj.kset = &bus->drivers; error = kobject_register(&drv->kobj); if (error) goto out_put_bus; //如果总线支持自动探测,则调用driver_attach。 if (drv->bus->drivers_autoprobe) { error = driver_attach(drv); if (error) goto out_unregister; } //将该驱动程序添加到总线上注册的所有驱动程序的链表中 klist_add_tail(&drv->knode_bus, &bus->klist_drivers); module_add_driver(drv->owner, drv); error = driver_create_file(drv, &driver_attr_uevent); if (error) { printk(KERN_ERR "%s: uevent attr (%s) failed\n", __FUNCTION__, drv->name); } error = driver_add_attrs(bus, drv); if (error) { /* How the hell do we get out of this pickle? Give up */ printk(KERN_ERR "%s: driver_add_attrs(%s) failed\n", __FUNCTION__, drv->name); } error = add_bind_files(drv); if (error) { /* Ditto */ printk(KERN_ERR "%s: add_bind_files(%s) failed\n", __FUNCTION__, drv->name); } return error; out_unregister: kobject_unregister(&drv->kobj); out_put_bus: bus_put(bus); return error; }
int dev_set_name(struct device *dev, const char *fmt, ...) { va_list vargs; int err, buflen; char buf[32]; va_start(vargs, fmt); buflen = vsprintf(buf, fmt, vargs); BUG_ON(buflen > sizeof(buf) - 1); va_end(vargs); err = kobject_set_name(&dev->kobj, buf); return err; }
static int __init mkset_init(void) { /* 创建并注册一个kset */ kset_p = kset_create_and_add("zjj", &mkset_ops, NULL); if(kset_p == NULL) return - EFAULT; kobject_set_name(&kset_c.kobj, "hc"); kset_c.kobj.kset = kset_p; kset_register(&kset_c); return 0; }
static int smschar_setup_cdev(struct smschar_device_t *dev, int index) { int rc, devno = MKDEV(smschar_major, smschar_minor + index); cdev_init(&dev->cdev, &smschar_fops); dev->cdev.owner = THIS_MODULE; dev->cdev.ops = &smschar_fops; kobject_set_name(&dev->cdev.kobj, "Siano_sms%d", index); rc = cdev_add(&dev->cdev, devno, 1); return rc; }
int mlog_sys_init(struct kset *o2cb_kset) { int i = 0; while (mlog_attrs[i].attr.mode) { mlog_attr_ptrs[i] = &mlog_attrs[i].attr; i++; } mlog_attr_ptrs[i] = NULL; kobject_set_name(&mlog_kset.kobj, "logmask"); mlog_kset.kobj.kset = o2cb_kset; return kset_register(&mlog_kset); }
static int __init mod_init(void) { dev_t major_nummer = MKDEV(MAJORNUM, 0); printk(KERN_ALERT "buf_threaded: Hello, world!\n"); if (register_chrdev_region(major_nummer, NUMDEVICES, DEVNAME)) { pr_warn("Device number 0x%x not available ...\n", MKDEV(MAJORNUM, 0)); return -EIO; } pr_info("Device number 0x%x created\n", MKDEV(MAJORNUM, 0)); cdev = cdev_alloc(); if (cdev == NULL) { pr_warn("cdev_alloc failed!\n"); goto free_devnum; } kobject_set_name(&cdev->kobj, DEVNAME); cdev->owner = THIS_MODULE; cdev_init(cdev, &fops); if (cdev_add(cdev, MKDEV(MAJORNUM, 0), NUMDEVICES)) { pr_warn("cdev_add failed!\n"); goto free_cdev; } dev_class = class_create(THIS_MODULE, DEVNAME); device_create(dev_class, NULL, major_nummer, NULL, DEVNAME); init_genstack(&stack, sizeof(char**), kfree); init_waitqueue_head(&wq_read); init_waitqueue_head(&wq_write); worker_queue = create_singlethread_workqueue("bufThread"); return 0; free_cdev: kobject_put(&cdev->kobj); cdev = NULL; free_devnum: unregister_chrdev_region(MKDEV(MAJORNUM, 0), NUMDEVICES); return -1; }
static int __init mod_init(void) { dev_t major_nummer = MKDEV(MAJORNUM, 0); atomic_set(&v, -1); printk(KERN_ALERT "Hello, world\n"); if (register_chrdev_region(MKDEV(MAJORNUM, 0), NUMDEVICES, DEVNAME)) { pr_warn("Device number 0x%x not available ...\n" , MKDEV(MAJORNUM, 0)); return -EIO ; } pr_info("Device number 0x%x created\n", MKDEV(MAJORNUM, 0)); cdev = cdev_alloc(); if (cdev == NULL) { pr_warn("cdev_alloc failed!\n"); goto free_devnum; } kobject_set_name(&cdev->kobj, DEVNAME); cdev->owner = THIS_MODULE; cdev_init(cdev, &fops); if (cdev_add(cdev, MKDEV(MAJORNUM,0), NUMDEVICES)) { pr_warn("cdev_add failed!\n"); goto free_cdev; } device = device; dev_class = class_create(THIS_MODULE, DEVNAME); device = device_create (dev_class, NULL, major_nummer, NULL, DEVNAME); return 0; free_cdev: kobject_put(&cdev->kobj); cdev = NULL; free_devnum: unregister_chrdev_region(MKDEV(MAJORNUM,0), NUMDEVICES); return -1; }
static int __init stmhdmi_register_device(struct stm_hdmi *hdmi, int id, dev_t firstdevice, struct stmcore_display_pipeline_data *platform_data) { cdev_init(&(hdmi->cdev),&hdmi_fops); hdmi->cdev.owner = THIS_MODULE; kobject_set_name(&(hdmi->cdev.kobj),"hdmi%d.0",id); if(cdev_add(&(hdmi->cdev),MKDEV(MAJOR(firstdevice),id),1)) return -ENODEV; if(stmhdmi_init_class_device(hdmi, platform_data)) return -ENODEV; return 0; }
/* * Register a cec device node * * The registration code assigns minor numbers and registers the new device node * with the kernel. An error is returned if no free minor number can be found, * or if the registration of the device node fails. * * Zero is returned on success. * * Note that if the cec_devnode_register call fails, the release() callback of * the cec_devnode structure is *not* called, so the caller is responsible for * freeing any data. */ static int __must_check cec_devnode_register(struct cec_devnode *devnode, struct module *owner) { int minor; int ret; /* Part 1: Find a free minor number */ mutex_lock(&cec_devnode_lock); minor = find_next_zero_bit(cec_devnode_nums, CEC_NUM_DEVICES, 0); if (minor == CEC_NUM_DEVICES) { mutex_unlock(&cec_devnode_lock); pr_err("could not get a free minor\n"); return -ENFILE; } set_bit(minor, cec_devnode_nums); mutex_unlock(&cec_devnode_lock); devnode->minor = minor; devnode->dev.bus = &cec_bus_type; devnode->dev.devt = MKDEV(MAJOR(cec_dev_t), minor); devnode->dev.release = cec_devnode_release; dev_set_name(&devnode->dev, "cec%d", devnode->minor); device_initialize(&devnode->dev); /* Part 2: Initialize and register the character device */ cdev_init(&devnode->cdev, &cec_devnode_fops); devnode->cdev.owner = owner; kobject_set_name(&devnode->cdev.kobj, "cec%d", devnode->minor); ret = cdev_device_add(&devnode->cdev, &devnode->dev); if (ret) { pr_err("%s: cdev_device_add failed\n", __func__); goto clr_bit; } devnode->registered = true; return 0; clr_bit: mutex_lock(&cec_devnode_lock); clear_bit(devnode->minor, cec_devnode_nums); mutex_unlock(&cec_devnode_lock); return ret; }
int __init f2fs_init_sysfs(void) { int ret; kobject_set_name(&f2fs_kset.kobj, "f2fs"); f2fs_kset.kobj.parent = fs_kobj; ret = kset_register(&f2fs_kset); if (ret) return ret; ret = kobject_init_and_add(&f2fs_feat, &f2fs_feat_ktype, NULL, "features"); if (ret) kset_unregister(&f2fs_kset); else f2fs_proc_root = proc_mkdir("fs/f2fs", NULL); return ret; }
/** * device_add - add device to device hierarchy. * @dev: device. * * This is part 2 of device_register(), though may be called * separately _iff_ device_initialize() has been called separately. * * This adds it to the kobject hierarchy via kobject_add(), adds it * to the global and sibling lists for the device, then * adds it to the other relevant subsystems of the driver model. */ int device_add(struct device *dev) { struct device *parent = NULL; int error = -EINVAL; dev = get_device(dev); if (!dev || !strlen(dev->bus_id)) goto Error; parent = get_device(dev->parent); pr_debug("DEV: registering device: ID = '%s'\n", dev->bus_id); /* first, register with generic layer. */ kobject_set_name(&dev->kobj, "%s", dev->bus_id); if (parent) dev->kobj.parent = &parent->kobj; if ((error = kobject_add(&dev->kobj))) goto Error; kobject_hotplug(&dev->kobj, KOBJ_ADD); if ((error = device_pm_add(dev))) goto PMError; if ((error = bus_add_device(dev))) goto BusError; if (parent) klist_add_tail(&parent->klist_children, &dev->knode_parent); /* notify platform of device entry */ if (platform_notify) platform_notify(dev); Done: put_device(dev); return error; BusError: device_pm_remove(dev); PMError: kobject_hotplug(&dev->kobj, KOBJ_REMOVE); kobject_del(&dev->kobj); Error: if (parent) put_device(parent); goto Done; }
void sysfs_rename_dir(struct kobject * kobj, const char *new_name) { struct dentry * new_dentry, * parent; if (!strcmp(kobject_name(kobj), new_name)) return; if (!kobj->parent) return; parent = kobj->parent->dentry; down(&parent->d_inode->i_sem); new_dentry = sysfs_get_dentry(parent, new_name); d_move(kobj->dentry, new_dentry); kobject_set_name(kobj,new_name); up(&parent->d_inode->i_sem); }
/** * bus_add_driver - Add a driver to the bus. * @drv: driver. * */ int bus_add_driver(struct device_driver *drv) { struct bus_type * bus = get_bus(drv->bus); int error = 0; if (!bus) return 0; pr_debug("bus %s: add driver %s\n", bus->name, drv->name); error = kobject_set_name(&drv->kobj, "%s", drv->name); if (error) goto out_put_bus; drv->kobj.kset = &bus->drivers; if ((error = kobject_register(&drv->kobj))) goto out_put_bus; error = driver_attach(drv); if (error) goto out_unregister; klist_add_tail(&drv->knode_bus, &bus->klist_drivers); module_add_driver(drv->owner, drv); error = driver_add_attrs(bus, drv); if (error) { /* How the hell do we get out of this pickle? Give up */ printk(KERN_ERR "%s: driver_add_attrs(%s) failed\n", __FUNCTION__, drv->name); } error = add_bind_files(drv); if (error) { /* Ditto */ printk(KERN_ERR "%s: add_bind_files(%s) failed\n", __FUNCTION__, drv->name); } return error; out_unregister: kobject_unregister(&drv->kobj); out_put_bus: put_bus(bus); return error; }
int gdlm_kobject_setup(struct gdlm_ls *ls, struct kobject *fskobj) { int error; error = kobject_set_name(&ls->kobj, "%s", "lock_module"); if (error) { log_error("can't set kobj name %d", error); return error; } ls->kobj.kset = &gdlm_kset; ls->kobj.ktype = &gdlm_ktype; ls->kobj.parent = fskobj; error = kobject_register(&ls->kobj); if (error) log_error("can't register kobj %d", error); return error; }
/* * kernel_param_sysfs_setup - wrapper for built-in params support */ static void __init kernel_param_sysfs_setup(const char *name, struct kernel_param *kparam, unsigned int num_params, unsigned int name_skip) { struct module_kobject *mk; int ret; mk = kzalloc(sizeof(struct module_kobject), GFP_KERNEL); BUG_ON(!mk); mk->mod = THIS_MODULE; kobj_set_kset_s(mk, module_subsys); kobject_set_name(&mk->kobj, name); kobject_init(&mk->kobj); ret = kobject_add(&mk->kobj); BUG_ON(ret < 0); param_sysfs_setup(mk, kparam, num_params, name_skip); kobject_uevent(&mk->kobj, KOBJ_ADD); }
/* * Add entries in sysfs onto the existing network class device * for the bridge. * Adds a attribute group "bridge" containing tuning parameters. * Binary attribute containing the forward table * Sub directory to hold links to interfaces. * * Note: the ifobj exists only to be a subdirectory * to hold links. The ifobj exists in same data structure * as it's parent the bridge so reference counting works. */ int br_sysfs_addbr(struct net_device *dev) { struct kobject *brobj = &dev->class_dev.kobj; struct net_bridge *br = netdev_priv(dev); int err; err = sysfs_create_group(brobj, &bridge_group); if (err) { pr_info("%s: can't create group %s/%s\n", __FUNCTION__, dev->name, bridge_group.name); goto out1; } err = sysfs_create_bin_file(brobj, &bridge_forward); if (err) { pr_info("%s: can't create attribue file %s/%s\n", __FUNCTION__, dev->name, bridge_forward.attr.name); goto out2; } kobject_set_name(&br->ifobj, SYSFS_BRIDGE_PORT_SUBDIR); br->ifobj.ktype = NULL; br->ifobj.kset = NULL; br->ifobj.parent = brobj; err = kobject_register(&br->ifobj); if (err) { pr_info("%s: can't add kobject (directory) %s/%s\n", __FUNCTION__, dev->name, br->ifobj.name); goto out3; } return 0; out3: sysfs_remove_bin_file(&dev->class_dev.kobj, &bridge_forward); out2: sysfs_remove_group(&dev->class_dev.kobj, &bridge_group); out1: return err; }
/* * kernel_param_sysfs_setup - wrapper for built-in params support */ static void __init kernel_param_sysfs_setup(const char *name, struct kernel_param *kparam, unsigned int num_params, unsigned int name_skip) { struct module_kobject *mk; mk = kmalloc(sizeof(struct module_kobject), GFP_KERNEL); memset(mk, 0, sizeof(struct module_kobject)); mk->mod = THIS_MODULE; kobj_set_kset_s(mk, module_subsys); kobject_set_name(&mk->kobj, name); kobject_register(&mk->kobj); /* no need to keep the kobject if no parameter is exported */ if (!param_sysfs_setup(mk, kparam, num_params, name_skip)) { kobject_unregister(&mk->kobj); kfree(mk); } }
int gfs2_sys_fs_add(struct gfs2_sbd *sdp) { int error; sdp->sd_kobj.kset = &gfs2_kset; sdp->sd_kobj.ktype = &gfs2_ktype; error = kobject_set_name(&sdp->sd_kobj, "%s", sdp->sd_table_name); if (error) goto fail; error = kobject_register(&sdp->sd_kobj); if (error) goto fail; error = sysfs_create_group(&sdp->sd_kobj, &lockstruct_group); if (error) goto fail_reg; error = sysfs_create_group(&sdp->sd_kobj, &args_group); if (error) goto fail_lockstruct; error = sysfs_create_group(&sdp->sd_kobj, &tune_group); if (error) goto fail_args; return 0; fail_args: sysfs_remove_group(&sdp->sd_kobj, &args_group); fail_lockstruct: sysfs_remove_group(&sdp->sd_kobj, &lockstruct_group); fail_reg: kobject_unregister(&sdp->sd_kobj); fail: fs_err(sdp, "error %d adding sysfs files", error); return error; }
int rfs_flt_sysfs_init(struct rfs_flt *rflt) { int rv; rflt->kobj.ktype = &rfs_flt_ktype; rflt->kobj.kset = rfs_flt_kset; kobject_init(&rflt->kobj); rv = kobject_set_name(&rflt->kobj, rflt->name); if (rv) return rv; rv = kobject_add(&rflt->kobj); if (rv) return rv; kobject_uevent(&rflt->kobj, KOBJ_ADD); rfs_flt_get(rflt); return 0; }
/* Initialize the device that is to be used with the PCI. */ static int nemaweaver_major_init(void) { static const char *name = "nemaweaver"; dev_t nema_dev = 0; int ret = 0; struct cdev *cdev = NULL; printk (KERN_INFO "Initializing character device.\n"); ret = alloc_chrdev_region(&nema_dev, 0, MAX_NEMAWEAVER_DEVS, name); if (ret) goto out; ret = -ENOMEM; cdev = cdev_alloc(); if (!cdev) goto out_unreg; cdev->owner = THIS_MODULE; cdev->ops = &nemaweaver_fops; kobject_set_name(&cdev->kobj, "%s", name); ret = cdev_add(cdev, nema_dev, MAX_NEMAWEAVER_DEVS); if (ret) goto out_put; nemaweaver_major = MAJOR(nema_dev); nemaweaver_cdev = cdev; printk (KERN_INFO "Nemaweaver device major number: %d\n", nemaweaver_major); return 0; out_put: kobject_put(&cdev->kobj); out_unreg: unregister_chrdev_region(nemaweaver_major, MAX_NEMAWEAVER_DEVS); out: return ret; }
static int recovery_button_prep_sysfs(void) { int err = 0; /* prep the sysfs interface for use */ kobject_set_name(&recovery_button_driver.kset.kobj, "recovery-button"); recovery_button_driver.kset.kobj.ktype = &ktype_recovery_button; err = kset_register(&recovery_button_driver.kset); if (err) return err; /* setup hotplugging */ recovery_button_driver.kset.uevent_ops = &recovery_button_uevent_ops; /* setup the heirarchy, the name will be set on detection */ kobject_init(&recovery_button_driver.recovery_button,recovery_button_driver.kset.kobj.ktype); recovery_button_driver.recovery_button.kset = kset_get(&recovery_button_driver.kset); recovery_button_driver.recovery_button.parent = &recovery_button_driver.kset.kobj; return 0; }
static int zpios_init(void) { dev_t dev; int rc; dev = MKDEV(ZPIOS_MAJOR, 0); if ((rc = register_chrdev_region(dev, ZPIOS_MINORS, ZPIOS_NAME))) goto error; /* Support for registering a character driver */ cdev_init(&zpios_cdev, &zpios_fops); zpios_cdev.owner = THIS_MODULE; kobject_set_name(&zpios_cdev.kobj, ZPIOS_NAME); if ((rc = cdev_add(&zpios_cdev, dev, ZPIOS_MINORS))) { printk(KERN_ERR "ZPIOS: Error adding cdev, %d\n", rc); kobject_put(&zpios_cdev.kobj); unregister_chrdev_region(dev, ZPIOS_MINORS); goto error; } /* Support for udev make driver info available in sysfs */ zpios_class = spl_class_create(THIS_MODULE, ZPIOS_NAME); if (IS_ERR(zpios_class)) { rc = PTR_ERR(zpios_class); printk(KERN_ERR "ZPIOS: Error creating zpios class, %d\n", rc); cdev_del(&zpios_cdev); unregister_chrdev_region(dev, ZPIOS_MINORS); goto error; } zpios_device = spl_device_create(zpios_class, NULL, dev, NULL, ZPIOS_NAME); return 0; error: printk(KERN_ERR "ZPIOS: Error registering zpios device, %d\n", rc); return rc; }