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

Commit d43e3bdb authored by Kiran Gunda's avatar Kiran Gunda Committed by Gerrit - the friendly Code Review server
Browse files

leds: qpnp-flash-v2: Acquire the bms_psy handle at runtime



Un-registering the power_supply notifier in its callback leads
to a "sleeping function from a invalid context" issue. Also, there
is no need to register for a power_supply notifier for the bms_psy
handle. Acquire this handle runtime, this also fixes the
sleeping-context issue.

Change-Id: I7c98446d88be3d2231ab30b53eebc0660e66b016
Signed-off-by: default avatarKiran Gunda <kgunda@codeaurora.org>
parent 2737e451
Loading
Loading
Loading
Loading
+5 −46
Original line number Diff line number Diff line
@@ -800,8 +800,11 @@ static int get_property_from_fg(struct qpnp_flash_led *led,
	union power_supply_propval pval = {0, };

	if (!led->bms_psy) {
		pr_err("no bms psy found\n");
		return -EINVAL;
		led->bms_psy = power_supply_get_by_name("bms");
		if (!led->bms_psy) {
			pr_err_ratelimited("Couldn't get bms_psy\n");
			return -ENODEV;
		}
	}

	rc = power_supply_get_property(led->bms_psy, prop, &pval);
@@ -1871,41 +1874,6 @@ static struct device_attribute qpnp_flash_led_attrs[] = {
	__ATTR(enable, 0664, NULL, qpnp_flash_led_prepare_store),
};

static int flash_led_psy_notifier_call(struct notifier_block *nb,
		unsigned long ev, void *v)
{
	struct power_supply *psy = v;
	struct qpnp_flash_led *led =
			container_of(nb, struct qpnp_flash_led, nb);

	if (ev != PSY_EVENT_PROP_CHANGED)
		return NOTIFY_OK;

	if (!strcmp(psy->desc->name, "bms")) {
		led->bms_psy = power_supply_get_by_name("bms");
		if (!led->bms_psy)
			pr_err("Failed to get bms power_supply\n");
		else
			power_supply_unreg_notifier(&led->nb);
	}

	return NOTIFY_OK;
}

static int flash_led_psy_register_notifier(struct qpnp_flash_led *led)
{
	int rc;

	led->nb.notifier_call = flash_led_psy_notifier_call;
	rc = power_supply_reg_notifier(&led->nb);
	if (rc < 0) {
		pr_err("Couldn't register psy notifier, rc = %d\n", rc);
		return rc;
	}

	return 0;
}

/* irq handler */
static irqreturn_t qpnp_flash_led_irq_handler(int irq, void *_led)
{
@@ -3090,15 +3058,6 @@ static int qpnp_flash_led_probe(struct platform_device *pdev)
	if (rc < 0)
		goto error_switch_register;

	led->bms_psy = power_supply_get_by_name("bms");
	if (!led->bms_psy) {
		rc = flash_led_psy_register_notifier(led);
		if (rc < 0) {
			pr_err("Couldn't register psy notifier, rc = %d\n", rc);
			goto error_switch_register;
		}
	}

	rc = qpnp_flash_led_init_settings(led);
	if (rc < 0) {
		pr_err("Failed to initialize flash LED, rc=%d\n", rc);