Пример #1
0
int hfi1_create_port_files(struct ib_device *ibdev, u8 port_num,
			   struct kobject *kobj)
{
	struct hfi1_pportdata *ppd;
	struct hfi1_devdata *dd = dd_from_ibdev(ibdev);
	int ret;

	if (!port_num || port_num > dd->num_pports) {
		dd_dev_err(dd,
			   "Skipping infiniband class with invalid port %u\n",
			   port_num);
		return -ENODEV;
	}
	ppd = &dd->pport[port_num - 1];

	ret = kobject_init_and_add(&ppd->sc2vl_kobj, &hfi1_sc2vl_ktype, kobj,
				   "sc2vl");
	if (ret) {
		dd_dev_err(dd,
			   "Skipping sc2vl sysfs info, (err %d) port %u\n",
			   ret, port_num);
		goto bail;
	}
	kobject_uevent(&ppd->sc2vl_kobj, KOBJ_ADD);

	ret = kobject_init_and_add(&ppd->sl2sc_kobj, &hfi1_sl2sc_ktype, kobj,
				   "sl2sc");
	if (ret) {
		dd_dev_err(dd,
			   "Skipping sl2sc sysfs info, (err %d) port %u\n",
			   ret, port_num);
		goto bail_sc2vl;
	}
	kobject_uevent(&ppd->sl2sc_kobj, KOBJ_ADD);

	ret = kobject_init_and_add(&ppd->vl2mtu_kobj, &hfi1_vl2mtu_ktype, kobj,
				   "vl2mtu");
	if (ret) {
		dd_dev_err(dd,
			   "Skipping vl2mtu sysfs info, (err %d) port %u\n",
			   ret, port_num);
		goto bail_sl2sc;
	}
	kobject_uevent(&ppd->vl2mtu_kobj, KOBJ_ADD);

	ret = kobject_init_and_add(&ppd->pport_cc_kobj, &port_cc_ktype,
				   kobj, "CCMgtA");
	if (ret) {
		dd_dev_err(dd,
			   "Skipping Congestion Control sysfs info, (err %d) port %u\n",
			   ret, port_num);
		goto bail_vl2mtu;
	}

	kobject_uevent(&ppd->pport_cc_kobj, KOBJ_ADD);

	ret = sysfs_create_bin_file(&ppd->pport_cc_kobj, &cc_setting_bin_attr);
	if (ret) {
		dd_dev_err(dd,
			   "Skipping Congestion Control setting sysfs info, (err %d) port %u\n",
			   ret, port_num);
		goto bail_cc;
	}

	ret = sysfs_create_bin_file(&ppd->pport_cc_kobj, &cc_table_bin_attr);
	if (ret) {
		dd_dev_err(dd,
			   "Skipping Congestion Control table sysfs info, (err %d) port %u\n",
			   ret, port_num);
		goto bail_cc_entry_bin;
	}

	dd_dev_info(dd,
		    "IB%u: Congestion Control Agent enabled for port %d\n",
		    dd->unit, port_num);

	return 0;

bail_cc_entry_bin:
	sysfs_remove_bin_file(&ppd->pport_cc_kobj,
			      &cc_setting_bin_attr);
bail_cc:
	kobject_put(&ppd->pport_cc_kobj);
bail_vl2mtu:
	kobject_put(&ppd->vl2mtu_kobj);
bail_sl2sc:
	kobject_put(&ppd->sl2sc_kobj);
bail_sc2vl:
	kobject_put(&ppd->sc2vl_kobj);
bail:
	return ret;
}
Пример #2
0
static int bu21150_probe(struct spi_device *client)
{
	struct bu21150_data *ts;
	int rc, i;

	ts = kzalloc(sizeof(struct bu21150_data), GFP_KERNEL);
	if (!ts) {
		dev_err(&client->dev, "Out of memory\n");
		return -ENOMEM;
	}

	/* parse dtsi */
	if (!parse_dtsi(&client->dev, ts)) {
		dev_err(&client->dev, "Invalid dtsi\n");
		rc = -EINVAL;
		goto err_parse_dt;
	}

	g_client_bu21150 = client;
	ts->client = client;

	rc = bu21150_pinctrl_init(ts);
	if (rc) {
		dev_err(&client->dev, "Pinctrl init failed\n");
		goto err_parse_dt;
	}

	rc = bu21150_regulator_config(ts, true);
	if (rc) {
		dev_err(&client->dev, "Failed to get power rail\n");
		goto err_regulator_config;
	}

	rc = bu21150_power_enable(ts, true);
	if (rc) {
		dev_err(&client->dev, "Power enablement failed\n");
		goto err_power_enable;
	}

	rc = bu21150_pin_enable(ts, true);
	if (rc) {
		dev_err(&client->dev, "Pin enable failed\n");
		goto err_pin_enable;
	}

	mutex_init(&ts->mutex_frame);
	init_waitqueue_head(&(ts->frame_waitq));

	ts->fb_notif.notifier_call = fb_notifier_callback;
	rc = fb_register_client(&ts->fb_notif);
	if (rc) {
		dev_err(&client->dev, "Unable to register fb_notifier: %d\n",
									rc);
		goto err_register_fb_notif;
	}

	rc = misc_register(&g_bu21150_misc_device);
	if (rc) {
		dev_err(&client->dev, "Failed to register misc device\n");
		goto err_register_misc;
	}

	dev_set_drvdata(&client->dev, ts);

	ts->bu21150_obj = kobject_create_and_add(SYSFS_PROPERTY_PATH, NULL);
	if (!ts->bu21150_obj) {
		dev_err(&client->dev, "unable to create kobject\n");
		goto err_create_and_add_kobj;
	}

	for (i = 0; i < ARRAY_SIZE(bu21150_prop_attrs); i++) {
		rc = sysfs_create_file(ts->bu21150_obj,
						&bu21150_prop_attrs[i].attr);
		if (rc) {
			dev_err(&client->dev, "failed to create attributes\n");
			goto err_create_sysfs;
		}
	}

	if (ts->wake_up)
		device_init_wakeup(&client->dev, ts->wake_up);

	mutex_init(&ts->mutex_wake);

	return 0;

err_create_sysfs:
	for (i--; i >= 0; i--)
		sysfs_remove_file(ts->bu21150_obj, &bu21150_prop_attrs[i].attr);
	kobject_put(ts->bu21150_obj);
err_create_and_add_kobj:
	misc_deregister(&g_bu21150_misc_device);
err_register_misc:
	fb_unregister_client(&ts->fb_notif);
err_register_fb_notif:
	mutex_destroy(&ts->mutex_frame);
	bu21150_pin_enable(ts, false);
err_pin_enable:
	bu21150_power_enable(ts, false);
err_power_enable:
	bu21150_regulator_config(ts, false);
err_regulator_config:
	if (ts->ts_pinctrl)
		devm_pinctrl_put(ts->ts_pinctrl);
err_parse_dt:
	kfree(ts);
	return rc;
}
Пример #3
0
/*
 * edac_device_create_block
 */
static int edac_device_create_block(struct edac_device_ctl_info *edac_dev,
				struct edac_device_instance *instance,
				struct edac_device_block *block)
{
	int i;
	int err;
	struct edac_dev_sysfs_block_attribute *sysfs_attrib;
	struct kobject *main_kobj;

	debugf4("%s() Instance '%s' inst_p=%p  block '%s'  block_p=%p\n",
		__func__, instance->name, instance, block->name, block);
	debugf4("%s() block kobj=%p  block kobj->parent=%p\n",
		__func__, &block->kobj, &block->kobj.parent);

	/* init this block's kobject */
	memset(&block->kobj, 0, sizeof(struct kobject));

	/* bump the main kobject's reference count for this controller
	 * and this instance is dependant on the main
	 */
	main_kobj = kobject_get(&edac_dev->kobj);
	if (!main_kobj) {
		err = -ENODEV;
		goto err_out;
	}

	/* Add this block's kobject */
	err = kobject_init_and_add(&block->kobj, &ktype_block_ctrl,
				   &instance->kobj,
				   "%s", block->name);
	if (err) {
		debugf1("%s() Failed to register instance '%s'\n",
			__func__, block->name);
		kobject_put(main_kobj);
		err = -ENODEV;
		goto err_out;
	}

	/* If there are driver level block attributes, then added them
	 * to the block kobject
	 */
	sysfs_attrib = block->block_attributes;
	if (sysfs_attrib && block->nr_attribs) {
		for (i = 0; i < block->nr_attribs; i++, sysfs_attrib++) {

			debugf4("%s() creating block attrib='%s' "
				"attrib->%p to kobj=%p\n",
				__func__,
				sysfs_attrib->attr.name,
				sysfs_attrib, &block->kobj);

			/* Create each block_attribute file */
			err = sysfs_create_file(&block->kobj,
				&sysfs_attrib->attr);
			if (err)
				goto err_on_attrib;
		}
	}
	kobject_uevent(&block->kobj, KOBJ_ADD);

	return 0;

	/* Error unwind stack */
err_on_attrib:
	kobject_put(&block->kobj);

err_out:
	return err;
}
static void __exit
ztemt_hw_version_exit(void)
{
    sysfs_remove_group(hw_version_kobj,&ztemt_hw_version_attr_group);
    kobject_put(hw_version_kobj);	
}
Пример #5
0
static void __exit proc_exit( void ) {
   kobject_put( asu_kobj );
   LOG( "module removed\n" );
}
Пример #6
0
/**
 * bus_add_driver - Add a driver to the bus.
 * @drv: driver.
 */
int bus_add_driver(struct device_driver *drv)
{
	struct bus_type *bus;
	struct driver_private *priv;
	int error = 0;

	bus = bus_get(drv->bus);
	if (!bus)
		return -EINVAL;

	pr_debug("bus: '%s': add driver %s\n", bus->name, drv->name);

	priv = kzalloc(sizeof(*priv), GFP_KERNEL);
	if (!priv) {
		error = -ENOMEM;
		goto out_put_bus;
	}
	klist_init(&priv->klist_devices, NULL, NULL);
	priv->driver = drv;
	drv->p = priv;
	priv->kobj.kset = bus->p->drivers_kset;
	error = kobject_init_and_add(&priv->kobj, &driver_ktype, NULL,
				     "%s", drv->name);
	if (error)
		goto out_unregister;

	if (drv->bus->p->drivers_autoprobe) {
		error = driver_attach(drv);
		if (error)
			goto out_unregister;
	}
	klist_add_tail(&priv->knode_bus, &bus->p->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",
			__func__, 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",
			__func__, drv->name);
	}

	if (!drv->suppress_bind_attrs) {
		error = add_bind_files(drv);
		if (error) {
			/* Ditto */
			printk(KERN_ERR "%s: add_bind_files(%s) failed\n",
				__func__, drv->name);
		}
	}

	kobject_uevent(&priv->kobj, KOBJ_ADD);
	return 0;

out_unregister:
	kobject_put(&priv->kobj);
	kfree(drv->p);
	drv->p = NULL;
out_put_bus:
	bus_put(bus);
	return error;
}
Пример #7
0
static void __exit autok_exit(void)
{      
    int i, j;  
    //kobject_put(args_kobj);
    kobject_put(stage2_kobj);
    kobject_put(stage1_kobj);
    kobject_put(autok_kobj);
    for(i=0; i<HOST_MAX_NUM*TOTAL_STAGE1_NODE_COUNT; i++){
        struct attribute *attr = *(stage1_attrs+i);
        //kfree(attr->name);
        kfree(attr);
        kfree(stage1_kattr[i]);
    }
    kfree(stage1_attrs);
    kfree(stage1_kattr);
    
    for(i=0; i<HOST_MAX_NUM; i++)
        kobject_put(s1_host_kobj[i]);
    kfree(s1_host_kobj);
    
    for(i=0; i<HOST_MAX_NUM; i++){
        struct attribute *attr = *(stage2_attrs+i);
        kfree(attr->name);
        kfree(attr);
        kfree(stage2_kattr[i]);
    }
    kfree(stage2_attrs);
    kfree(stage2_kattr);
    
    for(i=0; i<sizeof(host_nodes)/sizeof(host_nodes[0]); i++){
        struct attribute *attr = *(host_attrs+i);
        kfree(attr);
        kfree(host_kattr[i]);
    }
    
    kfree(host_attrs);
    kfree(host_kattr);
    
    for(i=0; i<HOST_MAX_NUM; i++){
        if(p_autok_predata[i].vol_count ==0 || p_autok_predata[i].vol_list == NULL)
            continue;
        kfree(p_autok_predata[i].vol_list);
        for(j=0; j<p_autok_predata[i].vol_count; j++){
            kfree(p_autok_predata[i].ai_data[j]);
        }
    }
    kfree(p_autok_predata);

    
    for(i=0; i<HOST_MAX_NUM; i++){
        if(p_single_autok[i].vol_count ==0 || p_single_autok[i].vol_list == NULL)
            continue;
        kfree(p_single_autok[i].vol_list);
        for(j=0; j<p_single_autok[i].vol_count; j++){
            kfree(p_single_autok[i].ai_data[j]);
        }
    }
    kfree(cur_voltage);
    kfree(p_single_autok);
    kfree(p_autok_thread_data->is_autok_done);
    kfree(p_autok_thread_data->p_autok_progress);
    kfree(p_autok_thread_data->autok_completion);
    //kthread_stop(task);
#ifdef AUTOK_THREAD    
    kfree(p_autok_thread_data);
#endif
    //debugfs_remove(autok_log_entry);
}
static int __init user_recovery_button_init(void)
{
	int err = 0;
	unsigned long flags;

	/* Prepare the sysfs interface for use */
	user_recovery_button_driver.kset = kset_create_and_add("user_recovery_button", &user_recovery_button_uevent_ops, kernel_kobj);
	if (!user_recovery_button_driver.kset) {
		printk(KERN_ERR "user_recovery_button_init() Failed to create kset\n");
		return -ENOMEM;
	}

	user_recovery_button_driver.kobject.kset = user_recovery_button_driver.kset;
	err = kobject_init_and_add(&user_recovery_button_driver.kobject,
		&ktype_user_recovery_button, NULL, "%d", 0);
	if (err) {
		printk(KERN_ERR "user_recovery_button_init() Failed to add kobject\n");
		kset_unregister(user_recovery_button_driver.kset);
		kobject_put(&user_recovery_button_driver.kobject);
		return -EINVAL;
	}

	/* Setup the timer that will time how long the user holds down the user
	   recovery button */
	init_timer(&timer);
	timer.data = 0;
	timer.function = timer_handler;

	/* Install a shared interrupt handler on the appropriate GPIO bank's
	   interrupt line */
	if (request_irq(IRQ_NUM, int_handler, IRQF_SHARED, "User Recovery Button", &user_recovery_button_driver)) {
		printk(KERN_ERR "User Recovery Button: cannot register IRQ %d\n", IRQ_NUM);
		del_timer_sync(&timer);
		return -EIO;
	}

	spin_lock_irqsave(&oxnas_gpio_spinlock, flags);
	/* Disable primary, secondary and teriary GPIO functions on switch lines */
#if defined(CONFIG_ARCH_OXNAS)
#if (CONFIG_OXNAS_USER_RECOVERY_BUTTON_GPIO < SYS_CTRL_NUM_PINS)
    writel(readl(SYS_CTRL_GPIO_PRIMSEL_CTRL_0) & ~SWITCH_MASK, SYS_CTRL_GPIO_PRIMSEL_CTRL_0);
    writel(readl(SYS_CTRL_GPIO_SECSEL_CTRL_0)  & ~SWITCH_MASK, SYS_CTRL_GPIO_SECSEL_CTRL_0);
    writel(readl(SYS_CTRL_GPIO_TERTSEL_CTRL_0) & ~SWITCH_MASK, SYS_CTRL_GPIO_TERTSEL_CTRL_0);
#else
    writel(readl(SYS_CTRL_GPIO_PRIMSEL_CTRL_1) & ~SWITCH_MASK, SYS_CTRL_GPIO_PRIMSEL_CTRL_1);
    writel(readl(SYS_CTRL_GPIO_SECSEL_CTRL_1)  & ~SWITCH_MASK, SYS_CTRL_GPIO_SECSEL_CTRL_1);
    writel(readl(SYS_CTRL_GPIO_TERTSEL_CTRL_1) & ~SWITCH_MASK, SYS_CTRL_GPIO_TERTSEL_CTRL_1);
#endif
#elif defined(CONFIG_ARCH_OX820)
#if (CONFIG_OXNAS_USER_RECOVERY_BUTTON_GPIO < SYS_CTRL_NUM_PINS)
    writel(readl(SYS_CTRL_SECONDARY_SEL)   & ~SWITCH_MASK, SYS_CTRL_SECONDARY_SEL);
    writel(readl(SYS_CTRL_TERTIARY_SEL)    & ~SWITCH_MASK, SYS_CTRL_TERTIARY_SEL);
    writel(readl(SYS_CTRL_QUATERNARY_SEL)  & ~SWITCH_MASK, SYS_CTRL_QUATERNARY_SEL);
    writel(readl(SYS_CTRL_DEBUG_SEL)       & ~SWITCH_MASK, SYS_CTRL_DEBUG_SEL);
    writel(readl(SYS_CTRL_ALTERNATIVE_SEL) & ~SWITCH_MASK, SYS_CTRL_ALTERNATIVE_SEL);
#else
    writel(readl(SEC_CTRL_SECONDARY_SEL)   & ~SWITCH_MASK, SEC_CTRL_SECONDARY_SEL);
    writel(readl(SEC_CTRL_TERTIARY_SEL)    & ~SWITCH_MASK, SEC_CTRL_TERTIARY_SEL);
    writel(readl(SEC_CTRL_QUATERNARY_SEL)  & ~SWITCH_MASK, SEC_CTRL_QUATERNARY_SEL);
    writel(readl(SEC_CTRL_DEBUG_SEL)       & ~SWITCH_MASK, SEC_CTRL_DEBUG_SEL);
    writel(readl(SEC_CTRL_ALTERNATIVE_SEL) & ~SWITCH_MASK, SEC_CTRL_ALTERNATIVE_SEL);
#endif
#endif

	/* Enable GPIO input on switch line */
	writel(SWITCH_MASK, SWITCH_CLR_OE_REG);

	/* Set up the user recovery button GPIO line for active low, debounced interrupt */
	writel(readl(DEBOUNCE_REG)    | SWITCH_MASK, DEBOUNCE_REG);
	writel(readl(LEVEL_INT_REG)   | SWITCH_MASK, LEVEL_INT_REG);
	writel(readl(FALLING_INT_REG) | SWITCH_MASK, FALLING_INT_REG);
	spin_unlock_irqrestore(&oxnas_gpio_spinlock, flags);

	printk(KERN_INFO "User recovery button driver registered\n");
	return 0;
}
static int edac_device_create_block(struct edac_device_ctl_info *edac_dev,
				struct edac_device_instance *instance,
				struct edac_device_block *block)
{
	int i;
	int err;
	struct edac_dev_sysfs_block_attribute *sysfs_attrib;
	struct kobject *main_kobj;

	debugf4("%s() Instance '%s' inst_p=%p  block '%s'  block_p=%p\n",
		__func__, instance->name, instance, block->name, block);
	debugf4("%s() block kobj=%p  block kobj->parent=%p\n",
		__func__, &block->kobj, &block->kobj.parent);

	
	memset(&block->kobj, 0, sizeof(struct kobject));

	main_kobj = kobject_get(&edac_dev->kobj);
	if (!main_kobj) {
		err = -ENODEV;
		goto err_out;
	}

	
	err = kobject_init_and_add(&block->kobj, &ktype_block_ctrl,
				   &instance->kobj,
				   "%s", block->name);
	if (err) {
		debugf1("%s() Failed to register instance '%s'\n",
			__func__, block->name);
		kobject_put(main_kobj);
		err = -ENODEV;
		goto err_out;
	}

	sysfs_attrib = block->block_attributes;
	if (sysfs_attrib && block->nr_attribs) {
		for (i = 0; i < block->nr_attribs; i++, sysfs_attrib++) {

			debugf4("%s() creating block attrib='%s' "
				"attrib->%p to kobj=%p\n",
				__func__,
				sysfs_attrib->attr.name,
				sysfs_attrib, &block->kobj);

			
			err = sysfs_create_file(&block->kobj,
				&sysfs_attrib->attr);
			if (err)
				goto err_on_attrib;
		}
	}
	kobject_uevent(&block->kobj, KOBJ_ADD);

	return 0;

	
err_on_attrib:
	kobject_put(&block->kobj);

err_out:
	return err;
}
Пример #10
0
static int __init po188_init(void)
{
    int err = -1;
    int ret = -1;
    struct kobject *kobj = NULL;
    struct regulator* ldo15_3v3;

    po188_driver.dev.name            = PO188_DEV_NAME;
    po188_driver.dev.minor           = MISC_DYNAMIC_MINOR;
    po188_driver.fops.unlocked_ioctl = po188_ioctl;
    po188_driver.dev.fops            = &po188_driver.fops;
    po188_driver.last_voltage        = 0;

    //set the initial delay value: 1s
    po188_driver.delay_time  = SENSOR_POLLING_JIFFIES; 
//    mutex_init(&po188_driver.lock);

    if ((err = misc_register(&po188_driver.dev)))
    {
        PO188_ERRMSG("misc_register failed");
        goto misc_register_failed;
    }

    //regulater config
    ldo15_3v3 = regulator_get(po188_driver.dev.this_device, "light-vcc");
    if (IS_ERR(ldo15_3v3)) {
        PO188_ERRMSG("cannot get po188 vcc drive");
        goto regulator_get_failed;
    }
    gPo188Regulator = ldo15_3v3;

    ret = regulator_set_voltage(ldo15_3v3, PO188_VCC_VOLTAGE, PO188_VCC_VOLTAGE);
    if (ret < 0) {
        PO188_ERRMSG("set po188 vcc drive error");
        goto regulator_set_voltage_failed;
    }
/*    ret = regulator_enable(ldo15_3v3);
    if (ret < 0) {
        PO188_ERRMSG("enable po188 vcc drive error");
        goto regulator_enable_failed;
    }*/

    po188_driver.po188_wq = create_singlethread_workqueue("po188_wq"); 
    if (!po188_driver.po188_wq) 
    {
        PO188_ERRMSG("create workque failed \n");
        goto create_singlethread_workqueue_failed;
    }

    //set time, and time overrun function
    init_timer(&po188_driver.timer);
    po188_driver.timer.expires = jiffies + msecs_to_jiffies( po188_driver.delay_time);
    po188_driver.timer.data = 0;
    po188_driver.timer.function = po188_start_cb_thread;
    //add_timer(&po188_driver.timer);

    po188_driver.input_dev = input_allocate_device();
    if (po188_driver.input_dev == NULL) {
        PO188_ERRMSG("po188_init : Failed to allocate input device\n");
        goto input_allocate_device_failed;
    }

    po188_driver.input_dev->name = PO188_DEV_NAME;
    input_set_drvdata(po188_driver.input_dev, &po188_driver);
    ret = input_register_device(po188_driver.input_dev);
    if (ret) {
        PO188_ERRMSG("Unable to register %s input device\n", po188_driver.input_dev->name);
        goto input_register_device_failed;
    }

    err = set_sensor_input(PO188, po188_driver.input_dev->dev.kobj.name);
    if (err) {
        PO188_ERRMSG("set_sensor_input error\n");
        goto set_sensor_input_failed;
    }

    set_bit(EV_ABS,po188_driver.input_dev->evbit);
    set_bit(EV_SYN,po188_driver.input_dev->evbit);
    input_set_abs_params(po188_driver.input_dev, ABS_MISC, 0, 10000, 0, 0);

/*no need early_suspend, the system can call enable/disable when suspend and resume*/
/*    po188_driver.early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1;
    po188_driver.early_suspend.suspend = Po188_suspend;
    po188_driver.early_suspend.resume = Po188_resume;
    register_early_suspend(&po188_driver.early_suspend);*/
    kobj = kobject_create_and_add(PO188_NAME, NULL);
    if (kobj == NULL) {
        goto kobject_create_and_add_failed;
    }
    if (sysfs_create_group(kobj, &po188_defattr_group)) {

        goto sysfs_create_group_failed;
    }

    spin_lock_init(&po188_driver.s_lock); 
    po188_driver.status_on = false;  //status_on must have init value

/*    //open adc channel
    ret = k3_adc_open_channel(PO188_ADC_CHANNEL);
    if (ret < 0)
    {
        PO188_ERRMSG("k3_adc_open_channel error\n");
        goto k3_adc_open_channel_failed;
    }*/

    return 0; 
 
//k3_adc_open_channel_failed:        
//  sysfs_remove_group(&po188_driver.dev.parent->kobj, &po188_defattr_group);
sysfs_create_group_failed:
    kobject_put(kobj);
kobject_create_and_add_failed:
set_sensor_input_failed:
    input_unregister_device(po188_driver.input_dev);
input_register_device_failed:
    input_free_device(po188_driver.input_dev);
input_allocate_device_failed:
    destroy_workqueue(po188_driver.po188_wq);
create_singlethread_workqueue_failed:
//   regulator_disable(ldo15_3v3);
//regulator_enable_failed:
regulator_set_voltage_failed:
    regulator_put(ldo15_3v3);
regulator_get_failed:
    misc_deregister(&po188_driver.dev);
misc_register_failed:
    return err;
}
Пример #11
0
static int add_port_entries(struct mlx4_ib_dev *device, int port_num)
{
	int i;
	char buff[10];
	struct mlx4_ib_iov_port *port = NULL;
	int ret = 0 ;
	struct ib_port_attr attr;

	/* get the physical gid and pkey table sizes.*/
	ret = __mlx4_ib_query_port(&device->ib_dev, port_num, &attr, 1);
	if (ret)
		goto err;

	port = &device->iov_ports[port_num - 1];
	port->dev = device;
	port->num = port_num;
	/* Directory structure:
	 * iov -
	 *   port num -
	 *	admin_guids
	 *	gids (operational)
	 *	mcg_table
	 */
	port->dentr_ar = kzalloc(sizeof (struct mlx4_ib_iov_sysfs_attr_ar),
				 GFP_KERNEL);
	if (!port->dentr_ar) {
		ret = -ENOMEM;
		goto err;
	}
	sprintf(buff, "%d", port_num);
	port->cur_port = kobject_create_and_add(buff,
				 kobject_get(device->ports_parent));
	if (!port->cur_port) {
		ret = -ENOMEM;
		goto kobj_create_err;
	}
	/* admin GUIDs */
	port->admin_alias_parent = kobject_create_and_add("admin_guids",
						  kobject_get(port->cur_port));
	if (!port->admin_alias_parent) {
		ret = -ENOMEM;
		goto err_admin_guids;
	}
	for (i = 0 ; i < attr.gid_tbl_len; i++) {
		sprintf(buff, "%d", i);
		port->dentr_ar->dentries[i].entry_num = i;
		ret = create_sysfs_entry(port, &port->dentr_ar->dentries[i],
					  buff, port->admin_alias_parent,
					  show_admin_alias_guid, store_admin_alias_guid);
		if (ret)
			goto err_admin_alias_parent;
	}

	/* gids subdirectory (operational gids) */
	port->gids_parent = kobject_create_and_add("gids",
						  kobject_get(port->cur_port));
	if (!port->gids_parent) {
		ret = -ENOMEM;
		goto err_gids;
	}

	for (i = 0 ; i < attr.gid_tbl_len; i++) {
		sprintf(buff, "%d", i);
		port->dentr_ar->dentries[attr.gid_tbl_len + i].entry_num = i;
		ret = create_sysfs_entry(port,
					 &port->dentr_ar->dentries[attr.gid_tbl_len + i],
					 buff,
					 port->gids_parent, show_port_gid, NULL);
		if (ret)
			goto err_gids_parent;
	}

	/* physical port pkey table */
	port->pkeys_parent =
		kobject_create_and_add("pkeys", kobject_get(port->cur_port));
	if (!port->pkeys_parent) {
		ret = -ENOMEM;
		goto err_pkeys;
	}

	for (i = 0 ; i < attr.pkey_tbl_len; i++) {
		sprintf(buff, "%d", i);
		port->dentr_ar->dentries[2 * attr.gid_tbl_len + i].entry_num = i;
		ret = create_sysfs_entry(port,
					 &port->dentr_ar->dentries[2 * attr.gid_tbl_len + i],
					 buff, port->pkeys_parent,
					 show_phys_port_pkey, NULL);
		if (ret)
			goto err_pkeys_parent;
	}

	/* MCGs table */
	port->mcgs_parent =
		kobject_create_and_add("mcgs", kobject_get(port->cur_port));
	if (!port->mcgs_parent) {
		ret = -ENOMEM;
		goto err_mcgs;
	}
	return 0;

err_mcgs:
	kobject_put(port->cur_port);

err_pkeys_parent:
	kobject_put(port->pkeys_parent);

err_pkeys:
	kobject_put(port->cur_port);

err_gids_parent:
	kobject_put(port->gids_parent);

err_gids:
	kobject_put(port->cur_port);

err_admin_alias_parent:
	kobject_put(port->admin_alias_parent);

err_admin_guids:
	kobject_put(port->cur_port);
	kobject_put(port->cur_port); /* once more for create_and_add buff */

kobj_create_err:
	kobject_put(device->ports_parent);
	kfree(port->dentr_ar);

err:
	pr_err("add_port_entries FAILED: for port:%d, error: %d\n",
	       port_num, ret);
	return ret;
}
_mali_osk_errcode_t mali_platform_init()
{
	int ret;

	is_running = false;
	mali_last_utilization = 0;

	if (!is_initialized) {

		prcmu_write(PRCMU_PLLSOC0, PRCMU_PLLSOC0_INIT);
		prcmu_write(PRCMU_SGACLK,  PRCMU_SGACLK_INIT);
		mali_boost_init();

		mali_utilization_workqueue = create_singlethread_workqueue("mali_utilization_workqueue");
		if (NULL == mali_utilization_workqueue) {
			MALI_DEBUG_PRINT(2, ("%s: Failed to setup workqueue %s\n", __func__, "mali_utilization_workqueue"));
			goto error;
		}

		INIT_WORK(&mali_utilization_work, mali_utilization_function);
		INIT_DELAYED_WORK(&mali_boost_delayedwork, mali_boost_work);

		regulator = regulator_get(NULL, "v-mali");
		if (IS_ERR(regulator)) {
			MALI_DEBUG_PRINT(2, ("%s: Failed to get regulator %s\n", __func__, "v-mali"));
			goto error;
		}

		clk_sga = clk_get_sys("mali", NULL);
		if (IS_ERR(clk_sga)) {
			regulator_put(regulator);
			MALI_DEBUG_PRINT(2, ("%s: Failed to get clock %s\n", __func__, "mali"));
			goto error;
		}

#if CONFIG_HAS_WAKELOCK
		wake_lock_init(&wakelock, WAKE_LOCK_SUSPEND, "mali_wakelock");
#endif

		mali_kobject = kobject_create_and_add("mali", kernel_kobj);
		if (!mali_kobject) {
			pr_err("[Mali] Failed to create kobject interface\n");
		}

		ret = sysfs_create_group(mali_kobject, &mali_interface_group);
		if (ret) {
			kobject_put(mali_kobject);
		}

		prcmu_qos_add_requirement(PRCMU_QOS_APE_OPP, "mali", PRCMU_QOS_DEFAULT_VALUE);
		prcmu_qos_add_requirement(PRCMU_QOS_DDR_OPP, "mali", PRCMU_QOS_DEFAULT_VALUE);

		pr_info("[Mali] DB8500 GPU OC Initialized (%s)\n", MALI_UX500_VERSION);

		is_initialized = true;
	}

	MALI_SUCCESS;
error:
	MALI_DEBUG_PRINT(1, ("SGA initialization failed.\n"));
	MALI_ERROR(_MALI_OSK_ERR_FAULT);
}
Пример #13
0
static void charger_control_remove(void)
{
	if (charger_control_kobj != NULL)
		kobject_put(charger_control_kobj);
}
Пример #14
0
static void destroy_foo_obj(struct foo_obj *foo)
{
	kobject_put(&foo->kobj);
}
Пример #15
0
static void ldlm_namespace_sysfs_unregister(struct ldlm_namespace *ns)
{
	kobject_put(&ns->ns_kobj);
	wait_for_completion(&ns->ns_kobj_unregister);
}
Пример #16
0
static void __exit lttng_benchmark_cleanup(void)
{
	kobject_put(lttng_benchmark_kobj);
}
Пример #17
0
void force_fast_charge_exit(void)
{
	kobject_put(force_fast_charge_kobj);
}
Пример #18
0
void dim2_sysfs_destroy(struct medialb_bus *bus)
{
	kobject_put(&bus->kobj_group);
}
Пример #19
0
static int fsl_otp_probe(struct platform_device *pdev)
{
	struct resource *res;
	struct attribute **attrs;
	const char **desc;
	int i, num;
	int ret;

	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
	otp_base = devm_ioremap_resource(&pdev->dev, res);
	if (IS_ERR(otp_base)) {
		ret = PTR_ERR(otp_base);
		dev_err(&pdev->dev, "failed to ioremap resource: %d\n", ret);
		return ret;
	}

	otp_clk = devm_clk_get(&pdev->dev, NULL);
	if (IS_ERR(otp_clk)) {
		ret = PTR_ERR(otp_clk);
		dev_err(&pdev->dev, "failed to get clock: %d\n", ret);
		return ret;
	}

	desc = (const char **) imx6q_otp_desc;
	num = sizeof(imx6q_otp_desc) / sizeof(void *);

	/* The last one is NULL, which is used to detect the end */
	attrs = devm_kzalloc(&pdev->dev, (num + 1) * sizeof(*attrs),
			     GFP_KERNEL);
	otp_kattr = devm_kzalloc(&pdev->dev, num * sizeof(*otp_kattr),
				 GFP_KERNEL);
	otp_attr_group = devm_kzalloc(&pdev->dev, sizeof(*otp_attr_group),
				      GFP_KERNEL);
	if (!attrs || !otp_kattr || !otp_attr_group)
		return -ENOMEM;

	for (i = 0; i < num; i++) {
		sysfs_attr_init(&otp_kattr[i].attr);
		otp_kattr[i].attr.name = desc[i];
		otp_kattr[i].attr.mode = 0600;
		otp_kattr[i].show = fsl_otp_show;
		otp_kattr[i].store = fsl_otp_store;
		attrs[i] = &otp_kattr[i].attr;
	}
	otp_attr_group->attrs = attrs;

	otp_kobj = kobject_create_and_add("fsl_otp", NULL);
	if (!otp_kobj) {
		dev_err(&pdev->dev, "failed to add kobject\n");
		return -ENOMEM;
	}

	ret = sysfs_create_group(otp_kobj, otp_attr_group);
	if (ret) {
		dev_err(&pdev->dev, "failed to create sysfs group: %d\n", ret);
		kobject_put(otp_kobj);
		return ret;
	}

	mutex_init(&otp_mutex);

	return 0;
}
Пример #20
0
static int baseband_xmm_power2_driver_probe(struct platform_device *device)
{
	struct baseband_power_platform_data *data
		= (struct baseband_power_platform_data *)
			device->dev.platform_data;

	int err=0;
	int err_radio;

	pr_debug("%s 0309 - CPU Freq with data protect.\n", __func__);

	if (data == NULL) {
		pr_err("%s: no platform data\n", __func__);
		return -EINVAL;
	}
	if (data->modem.xmm.hsic_device == NULL) {
		pr_err("%s: no hsic device\n", __func__);
		return -EINVAL;
	}

	/* save platform data */
	baseband_power2_driver_data = data;

	/* OEM specific initialization */
#ifdef BB_XMM_OEM1
		kobj_hsic_device =
			 kobject_get(&baseband_power2_driver_data->modem.xmm.hsic_device->dev.kobj);
		if (!kobj_hsic_device) {
			pr_err("[FLS] can not get modem_kobject\n");
			goto fail;
		}

		/* radio detect*/
		radio_detect_status = RADIO_STATUS_UNKNOWN;
		err_radio = request_irq(gpio_to_irq(CORE_DUMP_DETECT),
			radio_det_irq,
			/*IRQF_TRIGGER_RISING |*/ IRQF_TRIGGER_FALLING,
			"RADIO_DETECT",
			&modem_info);

		if (err_radio < 0) {
			pr_err("%s - request irq RADIO_DETECT failed\n",
				__func__);
		}
		radio_detect_status = RADIO_STATUS_READY;
		err_radio = gpio_get_value(CORE_DUMP_DETECT);
		pr_info("gpio CORE_DUMP_DETECT value is %d\n", err_radio);

		modem_kset_radio = kset_create_and_add("modem_coreDump", NULL, kobj_hsic_device);
		if (!modem_kset_radio) {
			kobject_put(kobj_hsic_device);
			pr_err("[FLS] can not allocate modem_kset_radiomodem_kset_radio%d\n", err);
			goto fail;
		}
		pr_info("init and add core dump into kobject\n");
		modem_info.modem_core_dump_kobj.kset = modem_kset_radio;
		err = kobject_init_and_add(&modem_info.modem_core_dump_kobj,
			&htc_modem_ktype, NULL, "htc_modem_radioio_det");
		if (err) {
			pr_err("init kobject modem_kset_radio failed.");
			kobject_put(&modem_info.modem_core_dump_kobj);
			kset_unregister(modem_kset_radio);
			modem_kset_radio = NULL;
			kobject_put(kobj_hsic_device);
			goto fail;
		}
#endif /* BB_XMM_OEM1 */

	/* init work queue */
	pr_debug("%s: init work queue\n", __func__);
	workqueue = create_singlethread_workqueue("baseband_xmm_power2_workqueue");

	if (!workqueue) {
		pr_err("cannot create workqueue\n");
		return -1;
	}

	baseband_xmm_power2_work = (struct baseband_xmm_power_work_t *)
		kmalloc(sizeof(struct baseband_xmm_power_work_t), GFP_KERNEL);

	if (!baseband_xmm_power2_work) {
		pr_err("cannot allocate baseband_xmm_power2_work\n");
		return -1;
	}
	pr_debug("%s: BBXMM_WORK_INIT\n", __func__);
	INIT_WORK((struct work_struct *) baseband_xmm_power2_work, baseband_xmm_power2_work_func);
	baseband_xmm_power2_work->state = BBXMM_WORK_INIT;
	queue_work(workqueue,
		(struct work_struct *) baseband_xmm_power2_work);

	/* init work queue */
#ifdef BB_XMM_OEM1
	INIT_WORK(&radio_detect_work_struct, radio_detect_work_handler);
fail:
#endif /* BB_XMM_OEM1 */

	return 0;
}
static int __devinit vkeys_probe(struct platform_device *pdev)
{
	struct vkeys_platform_data *pdata;
	int width, height, center_x, center_y;
	int x1 = 0, x2 = 0, i, c = 0, ret, border;
	char *name;

	vkey_buf = devm_kzalloc(&pdev->dev, MAX_BUF_SIZE, GFP_KERNEL);
	if (!vkey_buf) {
		dev_err(&pdev->dev, "Failed to allocate memory\n");
		return -ENOMEM;
	}

	if (pdev->dev.of_node) {
		pdata = devm_kzalloc(&pdev->dev,
			sizeof(struct vkeys_platform_data), GFP_KERNEL);
		if (!pdata) {
			dev_err(&pdev->dev, "Failed to allocate memory\n");
			return -ENOMEM;
		}

		ret = vkey_parse_dt(&pdev->dev, pdata);
		if (ret) {
			dev_err(&pdev->dev, "Parsing DT failed(%d)", ret);
			return ret;
		}
	} else
		pdata = pdev->dev.platform_data;

	if (!pdata || !pdata->name || !pdata->keycodes || !pdata->num_keys ||
		!pdata->disp_maxx || !pdata->disp_maxy || !pdata->panel_maxy) {
		dev_err(&pdev->dev, "pdata is invalid\n");
		return -EINVAL;
	}

	border = (pdata->panel_maxx - pdata->disp_maxx) * 2;
	width = ((pdata->disp_maxx - (border * (pdata->num_keys - 1)))
			/ pdata->num_keys);
	height = (pdata->panel_maxy - pdata->disp_maxy);
	center_y = pdata->disp_maxy + (height / 2) + pdata->y_offset;
	height = height * HEIGHT_SCALE_NUM / HEIGHT_SCALE_DENOM;

	x2 -= border * BORDER_ADJUST_NUM / BORDER_ADJUST_DENOM;

	for (i = 0; i < pdata->num_keys; i++) {
		x1 = x2 + border;
		x2 = x2 + border + width;
		center_x = x1 + (x2 - x1) / 2;
		printk("wangminrong i = %d add %d %d %d %d\r\n",i,center_x, center_y, width, height);
		#if 1
		if(i == 0)
		{
			center_x =  40;
			center_y = 530;
			width = 120;
			height = 100;
		}
		else if(i == 1)
		{
			center_x = 120;
			center_y = 530;
			width = 120;
			height = 100;
		}
		else if(i == 2)
		{
			center_x =  200;
			center_y = 530;
			width = 120;
			height = 100;
		}
		#endif
	      //  printk("wangminrong222 i = %d add %d %d %d %d\r\n",i,center_x, center_y, width, height);
		c += snprintf(vkey_buf + c, MAX_BUF_SIZE - c,
				"%s:%d:%d:%d:%d:%d\n",
				VKEY_VER_CODE, pdata->keycodes[i],
				center_x, center_y, width, height);
	        printk("keycodes= %d add %d %d %d %d\r\n",pdata->keycodes[i],center_x, center_y, width, height);
		
	}

	vkey_buf[c] = '\0';

	name = devm_kzalloc(&pdev->dev, sizeof(*name) * MAX_BUF_SIZE,
					GFP_KERNEL);
	if (!name)
		return -ENOMEM;

	snprintf(name, MAX_BUF_SIZE,
				"virtualkeys.%s", pdata->name);
	vkey_obj_attr.attr.name = name;

	vkey_obj = kobject_create_and_add("board_properties", NULL);
	if (!vkey_obj) {
		dev_err(&pdev->dev, "unable to create kobject\n");
		return -ENOMEM;
	}

	ret = sysfs_create_group(vkey_obj, &vkey_grp);
	if (ret) {
		dev_err(&pdev->dev, "failed to create attributes\n");
		goto destroy_kobj;
	}
	return 0;

destroy_kobj:
	kobject_put(vkey_obj);

	return ret;
}
Пример #22
0
struct ipcp_factory * ipcpf_register(struct ipcp_factories *         factories,
                                     const char *                    name,
                                     struct ipcp_factory_data *      data,
                                     const struct ipcp_factory_ops * ops)
{
        struct ipcp_factory * factory;

        LOG_DBG("Registering new factory");

        if (!string_is_ok(name)) {
                LOG_ERR("Name is bogus, cannot register factory");
                return NULL;
        }

        if (!ops_are_ok(ops)) {
                LOG_ERR("Cannot register factory '%s', ops are bogus", name);
                return NULL;
        }

        if (!factories) {
                LOG_ERR("Bogus parent, cannot register factory '%s", name);
                return NULL;
        }

        factory = ipcpf_find(factories, name);
        if (factory) {
                LOG_ERR("Factory '%s' already registered", name);
                return NULL;
        }

        LOG_DBG("Registering factory '%s'", name);

        factory = rkzalloc(sizeof(*factory), GFP_KERNEL);
        if (!factory)
                return NULL;

        factory->data      = data;
        factory->ops       = ops;
        factory->kobj.kset = factories->set;
        if (kobject_init_and_add(&factory->kobj, &ipcp_factory_ktype, NULL,
                                 "%s", name)) {
                LOG_ERR("Cannot add factory '%s' to the set", name);
                kobject_put(&factory->kobj);

                rkfree(factory);
                return NULL;
        }

        if (factory->ops->init(factory->data)) {
                LOG_ERR("Cannot initialize factory '%s'", name);
                kobject_put(&factory->kobj);
                rkfree(factory);
                return NULL;
        }

        /* Double checking for bugs */
        LOG_INFO("Factory '%s' registered successfully",
                 kobject_name(&factory->kobj));

        return factory;
}
static inline void
efivar_unregister(struct efivar_entry *var)
{
	kobject_put(&var->kobj);
}
Пример #24
0
void sysfs_del_hardif(struct kobject **hardif_obj)
{
	kobject_put(*hardif_obj);
	*hardif_obj = NULL;
}
static void sound_control_exit(void)
{
	if (sound_control_kobj != NULL)
		kobject_put(sound_control_kobj);
}
Пример #26
0
/**
 * put_driver - decrement driver's refcount.
 * @drv: driver.
 */
void put_driver(struct device_driver *drv)
{
	kobject_put(&drv->p->kobj);
}
Пример #27
0
static int check_perm(struct inode * inode, struct file * file)
{
	struct kobject *kobj = sysfs_get_kobject(file->f_dentry->d_parent);
	struct attribute * attr = to_attr(file->f_dentry);
	struct sysfs_buffer * buffer;
	struct sysfs_ops * ops = NULL;
	int error = 0;

	if (!kobj || !attr)
		goto Einval;

	/* Grab the module reference for this attribute if we have one */
	if (!try_module_get(attr->owner)) {
		error = -ENODEV;
		goto Done;
	}

	/* if the kobject has no ktype, then we assume that it is a subsystem
	 * itself, and use ops for it.
	 */
	if (kobj->kset && kobj->kset->ktype)
		ops = kobj->kset->ktype->sysfs_ops;
	else if (kobj->ktype)
		ops = kobj->ktype->sysfs_ops;
	else
		ops = &subsys_sysfs_ops;

	/* No sysfs operations, either from having no subsystem,
	 * or the subsystem have no operations.
	 */
	if (!ops)
		goto Eaccess;

	/* File needs write support.
	 * The inode's perms must say it's ok, 
	 * and we must have a store method.
	 */
	if (file->f_mode & FMODE_WRITE) {

		if (!(inode->i_mode & S_IWUGO) || !ops->store)
			goto Eaccess;

	}

	/* File needs read support.
	 * The inode's perms must say it's ok, and we there
	 * must be a show method for it.
	 */
	if (file->f_mode & FMODE_READ) {
		if (!(inode->i_mode & S_IRUGO) || !ops->show)
			goto Eaccess;
	}

	/* No error? Great, allocate a buffer for the file, and store it
	 * it in file->private_data for easy access.
	 */
	buffer = kmalloc(sizeof(struct sysfs_buffer),GFP_KERNEL);
	if (buffer) {
		memset(buffer,0,sizeof(struct sysfs_buffer));
		init_MUTEX(&buffer->sem);
		buffer->needs_read_fill = 1;
		buffer->ops = ops;
		file->private_data = buffer;
	} else
		error = -ENOMEM;
	goto Done;

 Einval:
	error = -EINVAL;
	goto Done;
 Eaccess:
	error = -EACCES;
	module_put(attr->owner);
 Done:
	if (error && kobj)
		kobject_put(kobj);
	return error;
}
Пример #28
0
void kgsl_pwrscale_close(struct kgsl_device *device)
{
	kobject_put(&device->pwrscale_kobj);
}
Пример #29
0
/*
 * edac_device_create_instance
 *	create just one instance of an edac_device 'instance'
 */
static int edac_device_create_instance(struct edac_device_ctl_info *edac_dev,
				int idx)
{
	int i, j;
	int err;
	struct edac_device_instance *instance;
	struct kobject *main_kobj;

	instance = &edac_dev->instances[idx];

	/* Init the instance's kobject */
	memset(&instance->kobj, 0, sizeof(struct kobject));

	instance->ctl = edac_dev;

	/* bump the main kobject's reference count for this controller
	 * and this instance is dependant on the main
	 */
	main_kobj = kobject_get(&edac_dev->kobj);
	if (!main_kobj) {
		err = -ENODEV;
		goto err_out;
	}

	/* Formally register this instance's kobject under the edac_device */
	err = kobject_init_and_add(&instance->kobj, &ktype_instance_ctrl,
				   &edac_dev->kobj, "%s", instance->name);
	if (err != 0) {
		debugf2("%s() Failed to register instance '%s'\n",
			__func__, instance->name);
		kobject_put(main_kobj);
		goto err_out;
	}

	debugf4("%s() now register '%d' blocks for instance %d\n",
		__func__, instance->nr_blocks, idx);

	/* register all blocks of this instance */
	for (i = 0; i < instance->nr_blocks; i++) {
		err = edac_device_create_block(edac_dev, instance,
						&instance->blocks[i]);
		if (err) {
			/* If any fail, remove all previous ones */
			for (j = 0; j < i; j++)
				edac_device_delete_block(edac_dev,
							&instance->blocks[j]);
			goto err_release_instance_kobj;
		}
	}
	kobject_uevent(&instance->kobj, KOBJ_ADD);

	debugf4("%s() Registered instance %d '%s' kobject\n",
		__func__, idx, instance->name);

	return 0;

	/* error unwind stack */
err_release_instance_kobj:
	kobject_put(&instance->kobj);

err_out:
	return err;
}
static int __init pseudo_init(void)
{ 
        
        int i,retval=0;
	printk("we are in init function \n");
	
	
	i = alloc_chrdev_region(&pdevice,0,1,"pseudo");  //for ndevices..
        if(i>0)
        {
	         printk("Error in device creating.....\n");
	        return -EBUSY;
        } 
    
	my_dev=kmalloc(sizeof(c_dev),GFP_KERNEL);
	if(my_dev==NULL)
	{
	         printk("error in creating devices\n");
	         unregister_chrdev_region(pdevice,1);
        }
       
 //       list_add_tail(&my_dev->list,&dev_list);   --- does not require this list

        //---------------------------------------------------------------------
	my_dev -> my_kobj = kobject_create_and_add("kobject_example", kernel_kobj);
	if (!(my_dev -> my_kobj))
		return -ENOMEM;

	retval = sysfs_create_group(my_dev->my_kobj, &attr_group);
	if (retval)
		kobject_put(my_dev->my_kobj);

	//----------------------------------------------------------------------
       
	my_dev->buff = kmalloc(MAX_BUFFSIZE,GFP_KERNEL);  // creating memory for buffer in kernel
	if(my_dev==NULL)
	{
		kfree(my_dev);
                unregister_chrdev_region(pdevice,1);
                return -ENOMEM;
        }
         
         kfifo_init(&(my_dev->kfifo),my_dev->buff,MAX_BUFFSIZE);   // ???
     	 if(&(my_dev->kfifo)==NULL)
         {
         	kfree(my_dev);
         	unregister_chrdev_region(pdevice,1);
         }
         
        cdev_init(&my_dev->cdev,&device_fops);         //device operations
      
         kobject_set_name(&(my_dev->cdev.kobj),"device0");//increment the reference count
        my_dev->cdev.ops = &device_fops;
         
        if(cdev_add(&my_dev->cdev,pdevice,1)<0)
          {
           printk("error in adding char device\n");
           kobject_put(&(my_dev->cdev.kobj));           // decrements the reference count &frees the object 
           kfifo_free(&my_dev->kfifo);
           //kfree(my_dev->buff);   //????

           kfree(my_dev);
           unregister_chrdev_region(pdevice,1);
           }
     
      printk(KERN_INFO "device has been loaded\n");
 	 
	return 0;


}