diff mbox series

[v5,1/9] gpio: qcom_pmic: fix silent dev_read_addr downcast

Message ID 20231130-b4-qcom-dt-compat-v5-1-41500e237ad0@linaro.org
State Superseded
Headers show
Series Qualcomm PMIC fixes | expand

Commit Message

Caleb Connolly Nov. 30, 2023, 8:22 p.m. UTC
priv->pid is uint32_t, but dev_read_addr() returns a uint64_t on arm64,
with the upper bits being used for error codes. Do error checking before
downcasting to u32 to prevent errors being silently ignored.

Reviewed-by: Sumit Garg <sumit.garg@linaro.org>
Signed-off-by: Caleb Connolly <caleb.connolly@linaro.org>
---
 drivers/gpio/qcom_pmic_gpio.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

Comments

Neil Armstrong Dec. 1, 2023, 9:32 a.m. UTC | #1
On 30/11/2023 21:22, Caleb Connolly wrote:
> priv->pid is uint32_t, but dev_read_addr() returns a uint64_t on arm64,
> with the upper bits being used for error codes. Do error checking before
> downcasting to u32 to prevent errors being silently ignored.
> 
> Reviewed-by: Sumit Garg <sumit.garg@linaro.org>
> Signed-off-by: Caleb Connolly <caleb.connolly@linaro.org>
> ---
>   drivers/gpio/qcom_pmic_gpio.c | 14 ++++++++++----
>   1 file changed, 10 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/gpio/qcom_pmic_gpio.c b/drivers/gpio/qcom_pmic_gpio.c
> index 65feb453ebc3..e5841f502953 100644
> --- a/drivers/gpio/qcom_pmic_gpio.c
> +++ b/drivers/gpio/qcom_pmic_gpio.c
> @@ -221,11 +221,14 @@ static int qcom_gpio_probe(struct udevice *dev)
>   {
>   	struct qcom_gpio_bank *priv = dev_get_priv(dev);
>   	int reg;
> +	u64 pid;
>   
> -	priv->pid = dev_read_addr(dev);
> -	if (priv->pid == FDT_ADDR_T_NONE)
> +	pid = dev_read_addr(dev);
> +	if (pid == FDT_ADDR_T_NONE)
>   		return log_msg_ret("bad address", -EINVAL);
>   
> +	priv->pid = pid;
> +
>   	/* Do a sanity check */
>   	reg = pmic_reg_read(dev->parent, priv->pid + REG_TYPE);
>   	if (reg != REG_TYPE_VAL)
> @@ -328,11 +331,14 @@ static int qcom_pwrkey_probe(struct udevice *dev)
>   {
>   	struct qcom_gpio_bank *priv = dev_get_priv(dev);
>   	int reg;
> +	u64 pid;
>   
> -	priv->pid = dev_read_addr(dev);
> -	if (priv->pid == FDT_ADDR_T_NONE)
> +	pid = dev_read_addr(dev);
> +	if (pid == FDT_ADDR_T_NONE)
>   		return log_msg_ret("bad address", -EINVAL);
>   
> +	priv->pid = pid;
> +
>   	/* Do a sanity check */
>   	reg = pmic_reg_read(dev->parent, priv->pid + REG_TYPE);
>   	if (reg != 0x1)
> 

Reviewed-by: Neil Armstrong <neil.armstrong@linaro.org>
diff mbox series

Patch

diff --git a/drivers/gpio/qcom_pmic_gpio.c b/drivers/gpio/qcom_pmic_gpio.c
index 65feb453ebc3..e5841f502953 100644
--- a/drivers/gpio/qcom_pmic_gpio.c
+++ b/drivers/gpio/qcom_pmic_gpio.c
@@ -221,11 +221,14 @@  static int qcom_gpio_probe(struct udevice *dev)
 {
 	struct qcom_gpio_bank *priv = dev_get_priv(dev);
 	int reg;
+	u64 pid;
 
-	priv->pid = dev_read_addr(dev);
-	if (priv->pid == FDT_ADDR_T_NONE)
+	pid = dev_read_addr(dev);
+	if (pid == FDT_ADDR_T_NONE)
 		return log_msg_ret("bad address", -EINVAL);
 
+	priv->pid = pid;
+
 	/* Do a sanity check */
 	reg = pmic_reg_read(dev->parent, priv->pid + REG_TYPE);
 	if (reg != REG_TYPE_VAL)
@@ -328,11 +331,14 @@  static int qcom_pwrkey_probe(struct udevice *dev)
 {
 	struct qcom_gpio_bank *priv = dev_get_priv(dev);
 	int reg;
+	u64 pid;
 
-	priv->pid = dev_read_addr(dev);
-	if (priv->pid == FDT_ADDR_T_NONE)
+	pid = dev_read_addr(dev);
+	if (pid == FDT_ADDR_T_NONE)
 		return log_msg_ret("bad address", -EINVAL);
 
+	priv->pid = pid;
+
 	/* Do a sanity check */
 	reg = pmic_reg_read(dev->parent, priv->pid + REG_TYPE);
 	if (reg != 0x1)