Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b388de88 authored by Dmitry Torokhov's avatar Dmitry Torokhov
Browse files

Input: axp20x-pek - switch over to using attribute group



Instead of registering device attributes individually let's use attribute
groups and also devm_* infrastructure to ease cleanup.

Tested-by: default avatarChen-Yu Tsai <wens@csie.org>
Signed-off-by: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
parent 5b6c26a9
Loading
Loading
Loading
Loading
+36 −28
Original line number Original line Diff line number Diff line
@@ -138,17 +138,28 @@ static ssize_t axp20x_store_ext_attr(struct device *dev,
				 axp20x_ea->mask, idx);
				 axp20x_ea->mask, idx);
	if (ret != 0)
	if (ret != 0)
		return -EINVAL;
		return -EINVAL;

	return count;
	return count;
}
}


static struct dev_ext_attribute axp20x_dev_attr_startup = {
static struct dev_ext_attribute axp20x_dev_attr_startup = {
	.attr	= __ATTR(startup, 0644, axp20x_show_ext_attr, axp20x_store_ext_attr),
	.attr	= __ATTR(startup, 0644, axp20x_show_ext_attr, axp20x_store_ext_attr),
	.var	= &axp20x_pek_startup_ext_attr
	.var	= &axp20x_pek_startup_ext_attr,
};
};


static struct dev_ext_attribute axp20x_dev_attr_shutdown = {
static struct dev_ext_attribute axp20x_dev_attr_shutdown = {
	.attr	= __ATTR(shutdown, 0644, axp20x_show_ext_attr, axp20x_store_ext_attr),
	.attr	= __ATTR(shutdown, 0644, axp20x_show_ext_attr, axp20x_store_ext_attr),
	.var	= &axp20x_pek_shutdown_ext_attr
	.var	= &axp20x_pek_shutdown_ext_attr,
};

static struct attribute *axp20x_attributes[] = {
	&axp20x_dev_attr_startup.attr.attr,
	&axp20x_dev_attr_shutdown.attr.attr,
	NULL,
};

static const struct attribute_group axp20x_attribute_group = {
	.attrs = axp20x_attributes,
};
};


static irqreturn_t axp20x_pek_irq(int irq, void *pwr)
static irqreturn_t axp20x_pek_irq(int irq, void *pwr)
@@ -166,6 +177,13 @@ static irqreturn_t axp20x_pek_irq(int irq, void *pwr)
	return IRQ_HANDLED;
	return IRQ_HANDLED;
}
}


static void axp20x_remove_sysfs_group(void *_data)
{
	struct device *dev = _data;

	sysfs_remove_group(&dev->kobj, &axp20x_attribute_group);
}

static int axp20x_pek_probe(struct platform_device *pdev)
static int axp20x_pek_probe(struct platform_device *pdev)
{
{
	struct axp20x_pek *axp20x_pek;
	struct axp20x_pek *axp20x_pek;
@@ -219,7 +237,6 @@ static int axp20x_pek_probe(struct platform_device *pdev)
	if (error < 0) {
	if (error < 0) {
		dev_err(axp20x->dev, "Failed to request dbr IRQ#%d: %d\n",
		dev_err(axp20x->dev, "Failed to request dbr IRQ#%d: %d\n",
			axp20x_pek->irq_dbr, error);
			axp20x_pek->irq_dbr, error);

		return error;
		return error;
	}
	}


@@ -232,45 +249,36 @@ static int axp20x_pek_probe(struct platform_device *pdev)
		return error;
		return error;
	}
	}


	error = device_create_file(&pdev->dev, &axp20x_dev_attr_startup.attr);
	error = sysfs_create_group(&pdev->dev.kobj, &axp20x_attribute_group);
	if (error)
	if (error) {
		dev_err(axp20x->dev, "Failed to create sysfs attributes: %d\n",
			error);
		return error;
		return error;
	}


	error = device_create_file(&pdev->dev, &axp20x_dev_attr_shutdown.attr);
	error = devm_add_action(&pdev->dev,
	if (error)
				axp20x_remove_sysfs_group, &pdev->dev);
		goto clear_startup_attr;
	if (error) {
		axp20x_remove_sysfs_group(&pdev->dev);
		dev_err(&pdev->dev, "Failed to add sysfs cleanup action: %d\n",
			error);
		return error;
	}


	error = input_register_device(idev);
	error = input_register_device(idev);
	if (error) {
	if (error) {
		dev_err(axp20x->dev, "Can't register input device: %d\n",
		dev_err(axp20x->dev, "Can't register input device: %d\n",
			error);
			error);
		goto clear_attr;
	}

	platform_set_drvdata(pdev, axp20x_pek);

	return 0;

clear_attr:
	device_remove_file(&pdev->dev, &axp20x_dev_attr_shutdown.attr);

clear_startup_attr:
	device_remove_file(&pdev->dev, &axp20x_dev_attr_startup.attr);

		return error;
		return error;
	}
	}


static int axp20x_pek_remove(struct platform_device *pdev)
	platform_set_drvdata(pdev, axp20x_pek);
{
	device_remove_file(&pdev->dev, &axp20x_dev_attr_shutdown.attr);
	device_remove_file(&pdev->dev, &axp20x_dev_attr_startup.attr);


	return 0;
	return 0;
}
}


static struct platform_driver axp20x_pek_driver = {
static struct platform_driver axp20x_pek_driver = {
	.probe		= axp20x_pek_probe,
	.probe		= axp20x_pek_probe,
	.remove		= axp20x_pek_remove,
	.driver		= {
	.driver		= {
		.name		= "axp20x-pek",
		.name		= "axp20x-pek",
	},
	},