int diagcmd_dev_register(struct diagcmd_dev *sdev)
{
	int ret;

	if (!lg_fw_diag_class) {
		ret = create_lg_fw_diag_class();
		if (ret < 0)
			return ret;
	}

	sdev->index = atomic_inc_return(&device_count);
	sdev->dev = device_create(lg_fw_diag_class, NULL,
		MKDEV(0, sdev->index), NULL, sdev->name);
	if (IS_ERR(sdev->dev))
		return PTR_ERR(sdev->dev);

	ret = device_create_file(sdev->dev, &dev_attr_state);
	if (ret < 0)
		goto err_create_file_1;
	ret = device_create_file(sdev->dev, &dev_attr_name);
	if (ret < 0)
		goto err_create_file_2;
	// LGE_CHANGE_S [[email protected]] [2011.02.21] [gelato] add diag sysfs [START]
	ret = device_create_file(sdev->dev, &dev_attr_result);
	if (ret < 0)
		goto err_create_file_3;
	ret = device_create_file(sdev->dev, &dev_attr_return);
	if (ret < 0)
		goto err_create_file_4;
	// LGE_CHANGE_E [[email protected]] [2011.02.21] [gelato] add diag sysfs [END]
// LGE_CHANGE_S [[email protected]] [2011.02.21] [M3S] add diag sysfs [START]
	ret = device_create_file(sdev->dev, &dev_attr_nfc_testmode_result);
	if (ret < 0)
		goto err_create_file_5;
// LGE_CHANGE_S [[email protected]] [2011.02.21] [M3S] add diag sysfs [END]

	dev_set_drvdata(sdev->dev, sdev);
	sdev->state = 0;
	return 0;

// LGE_CHANGE_S [[email protected]] [2011.02.21] [gelato] add diag sysfs [START]

// LGE_CHANGE_S [[email protected]] [2011.02.21] [M3S] add diag sysfs [START]
err_create_file_5:
// LGE_CHANGE_S [[email protected]] [2011.02.21] [gelato] add diag sysfs [START]
	device_remove_file(sdev->dev, &dev_attr_nfc_testmode_result);
// LGE_CHANGE_S [[email protected]] [2011.02.21] [M3S] add diag sysfs [END]
err_create_file_4:
	device_remove_file(sdev->dev, &dev_attr_return);
err_create_file_3:
	device_remove_file(sdev->dev, &dev_attr_result);
// LGE_CHANGE_E [[email protected]] [2011.02.21] [gelato] add diag sysfs [END]
err_create_file_2:
	device_remove_file(sdev->dev, &dev_attr_state);
err_create_file_1:
	device_destroy(lg_fw_diag_class, MKDEV(0, sdev->index));
	printk(KERN_ERR "lg_fw_diagcmd: Failed to register driver %s\n", sdev->name);

	return ret;
}
int diagcmd_dev_register(struct diagcmd_dev *sdev)
{
	int ret;

	if (!lg_fw_diag_class) {
		ret = create_lg_fw_diag_class();
		if (ret < 0)
			return ret;
	}

	sdev->index = atomic_inc_return(&device_count);
	sdev->dev = device_create(lg_fw_diag_class, NULL,
		MKDEV(0, sdev->index), NULL, sdev->name);
	if (IS_ERR(sdev->dev))
		return PTR_ERR(sdev->dev);

	ret = device_create_file(sdev->dev, &dev_attr_state);
	if (ret < 0)
		goto err_create_file_1;
	ret = device_create_file(sdev->dev, &dev_attr_name);
	if (ret < 0)
		goto err_create_file_2;

	dev_set_drvdata(sdev->dev, sdev);
	sdev->state = 0;
	return 0;

err_create_file_2:
	device_remove_file(sdev->dev, &dev_attr_state);
err_create_file_1:
	device_destroy(lg_fw_diag_class, MKDEV(0, sdev->index));
	printk(KERN_ERR "lg_fw_diagcmd: Failed to register driver %s\n", sdev->name);

	return ret;
}
static int __init lg_fw_diag_class_init(void)
{
	return create_lg_fw_diag_class();
}