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

Commit 559731a7 authored by Mathew King's avatar Mathew King Committed by Greg Kroah-Hartman
Browse files

UPSTREAM: power: supply: core: Add type property to uevent env



Add POWER_SUPPLY_TYPE to the uevent env for power supply. Type is a
property of all power supplies and there is a sysfs entry for it but it
is not included in the properties array of the power supply so
explicitly add it to the udev env.

Signed-off-by: default avatarMathew King <mathewk@chromium.org>
Signed-off-by: default avatarSebastian Reichel <sebastian.reichel@collabora.com>
(cherry picked from commit 2ad3d74e3c69fb371412f37d8226f2da3a3b6cc2)
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@google.com>
Change-Id: Ibf8d580267f2143e1083599845fdb1c806f6917f
parent fdeaf705
Loading
Loading
Loading
Loading
+37 −24
Original line number Diff line number Diff line
@@ -411,6 +411,37 @@ void power_supply_init_attrs(struct device_type *dev_type)
	}
}

static int add_prop_uevent(struct device *dev, struct kobj_uevent_env *env,
			   enum power_supply_property prop, char *prop_buf)
{
	int ret = 0;
	struct power_supply_attr *pwr_attr;
	struct device_attribute *dev_attr;
	char *line;

	pwr_attr = &power_supply_attrs[prop];
	dev_attr = &pwr_attr->dev_attr;

	ret = power_supply_show_property(dev, dev_attr, prop_buf);
	if (ret == -ENODEV || ret == -ENODATA) {
		/*
		 * When a battery is absent, we expect -ENODEV. Don't abort;
		 * send the uevent with at least the the PRESENT=0 property
		 */
		return 0;
	}

	if (ret < 0)
		return ret;

	line = strchr(prop_buf, '\n');
	if (line)
		*line = 0;

	return add_uevent_var(env, "POWER_SUPPLY_%s=%s",
			      pwr_attr->prop_name, prop_buf);
}

int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env)
{
	struct power_supply *psy = dev_get_drvdata(dev);
@@ -430,31 +461,13 @@ int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env)
	if (!prop_buf)
		return -ENOMEM;

	for (j = 0; j < psy->desc->num_properties; j++) {
		struct power_supply_attr *pwr_attr;
		struct device_attribute *dev_attr;
		char *line;

		pwr_attr = &power_supply_attrs[psy->desc->properties[j]];
		dev_attr = &pwr_attr->dev_attr;

		ret = power_supply_show_property(dev, dev_attr, prop_buf);
		if (ret == -ENODEV || ret == -ENODATA) {
			/* When a battery is absent, we expect -ENODEV. Don't abort;
			   send the uevent with at least the the PRESENT=0 property */
			ret = 0;
			continue;
		}

		if (ret < 0)
	ret = add_prop_uevent(dev, env, POWER_SUPPLY_PROP_TYPE, prop_buf);
	if (ret)
		goto out;

		line = strchr(prop_buf, '\n');
		if (line)
			*line = 0;

		ret = add_uevent_var(env, "POWER_SUPPLY_%s=%s",
				     pwr_attr->prop_name, prop_buf);
	for (j = 0; j < psy->desc->num_properties; j++) {
		ret = add_prop_uevent(dev, env, psy->desc->properties[j],
				      prop_buf);
		if (ret)
			goto out;
	}