From 587f346193f763bcc42b2f8fceb3e603866b0e02 Mon Sep 17 00:00:00 2001 From: Guru Das Srinagesh Date: Thu, 23 Jan 2020 19:17:05 -0800 Subject: [PATCH] pwm: pwm-qti-lpg: Handle nvmem device lookup failure properly Due to commit 95b65195d571ab5 ("nvmem: core: Always reference the device returned by nvmem_device_get()") failures in nvmem device lookup return -EPROBE_DEFER instead of NULL. This causes probe failure of the pwm-qti-lpg driver when pwm devices are defined in the device tree without nvmem nodes, which is undesirable. Fix this by attempting to get the nvmem device only if it is present. Change-Id: Ifa136bb9b78e4b9e0894854768e9a6cc060d5261 Signed-off-by: Guru Das Srinagesh --- drivers/pwm/pwm-qti-lpg.c | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/drivers/pwm/pwm-qti-lpg.c b/drivers/pwm/pwm-qti-lpg.c index 648744526cde..8fe6ac0257f4 100644 --- a/drivers/pwm/pwm-qti-lpg.c +++ b/drivers/pwm/pwm-qti-lpg.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-only /* - * Copyright (c) 2018-2019, The Linux Foundation. All rights reserved. + * Copyright (c) 2018-2020, The Linux Foundation. All rights reserved. */ #define pr_fmt(fmt) "%s: " fmt, __func__ @@ -1277,22 +1277,16 @@ static int qpnp_lpg_parse_dt(struct qpnp_lpg_chip *chip) if (!chip->lut) return -ENOMEM; - chip->sdam_nvmem = devm_nvmem_device_get(chip->dev, "ppg_sdam"); - if (IS_ERR_OR_NULL(chip->sdam_nvmem)) { - if (PTR_ERR(chip->sdam_nvmem) == -EPROBE_DEFER) - return -EPROBE_DEFER; - - addr = of_get_address(chip->dev->of_node, 1, NULL, NULL); - if (!addr) { - pr_debug("NO LUT address assigned\n"); - devm_kfree(chip->dev, chip->lut); - chip->lut = NULL; - return 0; + 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); + if (rc != -EPROBE_DEFER) + dev_err(chip->dev, "Read nvmem device failed, rc=%d\n", + rc); + return rc; } - chip->lut->reg_base = be32_to_cpu(*addr); - max_count = LPG_LUT_COUNT_MAX; - } else { chip->use_sdam = true; chip->pbs_dev_node = of_parse_phandle(chip->dev->of_node, "qcom,pbs-client", 0); @@ -1311,6 +1305,17 @@ static int qpnp_lpg_parse_dt(struct qpnp_lpg_chip *chip) } max_count = SDAM_LUT_COUNT_MAX; + } else { + addr = of_get_address(chip->dev->of_node, 1, NULL, NULL); + if (!addr) { + pr_debug("NO LUT address assigned\n"); + devm_kfree(chip->dev, chip->lut); + chip->lut = NULL; + return 0; + } + + chip->lut->reg_base = be32_to_cpu(*addr); + max_count = LPG_LUT_COUNT_MAX; } chip->lut->chip = chip;