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

Commit 9f5b5d01 authored by Guru Das Srinagesh's avatar Guru Das Srinagesh
Browse files

pwm: qti-lpg: Fix erroneous clearing of LUT



The memory allocated for the lookup table (LUT) is getting cleared even
when a valid nvmem and PBS configuration is detected. Fix this by
ensuring that this happens only when neither a LUT peripheral's address
nor a valid nvmem configuration is detected.

Fixes: 218908e8 ("pwm: pwm-qti-lpg: Refactor qpnp_lpg_parse_dt() for
readability").

Change-Id: I59467d46779e0a01bf0843863680ec2a8f85f2ce
Signed-off-by: default avatarGuru Das Srinagesh <gurus@codeaurora.org>
parent 875a7675
Loading
Loading
Loading
Loading
+16 −9
Original line number Diff line number Diff line
@@ -1477,11 +1477,12 @@ static int qpnp_lpg_parse_dt(struct qpnp_lpg_chip *chip)
		}
	}

	chip->lut = devm_kmalloc(chip->dev, sizeof(*chip->lut), GFP_KERNEL);
	if (of_find_property(chip->dev->of_node, "nvmem", NULL)) {
		chip->lut = devm_kmalloc(chip->dev, sizeof(*chip->lut),
				GFP_KERNEL);
		if (!chip->lut)
			return -ENOMEM;

	if (of_find_property(chip->dev->of_node, "nvmem", NULL)) {
		chip->sdam_nvmem = devm_nvmem_device_get(chip->dev, "ppg_sdam");
		if (IS_ERR_OR_NULL(chip->sdam_nvmem)) {
			rc = PTR_ERR(chip->sdam_nvmem);
@@ -1514,13 +1515,19 @@ static int qpnp_lpg_parse_dt(struct qpnp_lpg_chip *chip)
			return rc;
		}
	} else if (lut_is_defined(chip, &addr)) {
		chip->lut = devm_kmalloc(chip->dev, sizeof(*chip->lut),
				GFP_KERNEL);
		if (!chip->lut)
			return -ENOMEM;

		chip->lut->reg_base = be32_to_cpu(*addr);
		return qpnp_lpg_parse_pattern_dt(chip, LPG_LUT_COUNT_MAX);
	}

		rc = qpnp_lpg_parse_pattern_dt(chip, LPG_LUT_COUNT_MAX);
		if (rc < 0)
			return rc;
	} else {
		pr_debug("Neither SDAM nor LUT specified\n");
	devm_kfree(chip->dev, chip->lut);
	chip->lut = NULL;
	}

	return 0;
}