[PATCH] usb: typec: qcom-pmic: fix uninitialized value hdr_len and txbuf_len

Rex Nie posted 1 patch 3 weeks, 6 days ago
drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] usb: typec: qcom-pmic: fix uninitialized value hdr_len and txbuf_len
Posted by Rex Nie 3 weeks, 6 days ago
If the read of USB_PDPHY_RX_ACKNOWLEDGE_REG failed, then hdr_len and
txbuf_len are uninitialized. It makes no sense to print message header
and payload. It is also not safe to print uninitialized length of ram.

Signed-off-by: Rex Nie <rex.nie@jaguarmicro.com>
---
 drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c b/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c
index 5b7f52b74a40..53c2180a773a 100644
--- a/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c
+++ b/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c
@@ -221,7 +221,7 @@ qcom_pmic_typec_pdphy_pd_transmit_payload(struct pmic_typec_pdphy *pmic_typec_pd
 					  unsigned int negotiated_rev)
 {
 	struct device *dev = pmic_typec_pdphy->dev;
-	unsigned int val, hdr_len, txbuf_len, txsize_len;
+	unsigned int val, hdr_len = 0, txbuf_len = 0, txsize_len;
 	unsigned long flags;
 	int ret;
 
-- 
2.17.1
Re: [PATCH] usb: typec: qcom-pmic: fix uninitialized value hdr_len and txbuf_len
Posted by Bjorn Andersson 3 weeks, 5 days ago
On Tue, Oct 29, 2024 at 10:18:23AM GMT, Rex Nie wrote:
> If the read of USB_PDPHY_RX_ACKNOWLEDGE_REG failed, then hdr_len and
> txbuf_len are uninitialized. It makes no sense to print message header
> and payload. It is also not safe to print uninitialized length of ram.
> 
> Signed-off-by: Rex Nie <rex.nie@jaguarmicro.com>
> ---
>  drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c b/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c
> index 5b7f52b74a40..53c2180a773a 100644
> --- a/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c
> +++ b/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c
> @@ -221,7 +221,7 @@ qcom_pmic_typec_pdphy_pd_transmit_payload(struct pmic_typec_pdphy *pmic_typec_pd
>  					  unsigned int negotiated_rev)
>  {
>  	struct device *dev = pmic_typec_pdphy->dev;
> -	unsigned int val, hdr_len, txbuf_len, txsize_len;
> +	unsigned int val, hdr_len = 0, txbuf_len = 0, txsize_len;

This stops us from printing uninitialized values, but the error print is
now containing misleading/false data instead.

As far as I can tell, the assignment of these three variables depend
only on the  "msg" argument passed to the function, not on the
operations leading up to their assignment.

So how about just moving the 3 assignments up to the top of the function
instead?

Regards,
Bjorn

>  	unsigned long flags;
>  	int ret;
>  
> -- 
> 2.17.1
> 
>
Re: [PATCH] usb: typec: qcom-pmic: fix uninitialized value hdr_len and txbuf_len
Posted by Bryan O'Donoghue 3 weeks, 5 days ago
On 29/10/2024 15:28, Bjorn Andersson wrote:
>> +	unsigned int val, hdr_len = 0, txbuf_len = 0, txsize_len;
> This stops us from printing uninitialized values, but the error print is
> now containing misleading/false data instead.

Yes, the point of the error printout is to also give an indication of 
what data didn't transmit

         hdr_len = sizeof(msg->header);
         txbuf_len = pd_header_cnt_le(msg->header) * 4;

The default values of the header should probably just be latched @ the 
top of this routine.

We assume *msg contains valid data so instead of init to zero we should 
init as above.

Please do that for your V2 including

Fixes: a4422ff22142 (" usb: typec: qcom: Add Qualcomm PMIC Type-C driver")

---
bod
Re: [PATCH] usb: typec: qcom-pmic: fix uninitialized value hdr_len and txbuf_len
Posted by Greg KH 3 weeks, 6 days ago
On Tue, Oct 29, 2024 at 10:18:23AM +0800, Rex Nie wrote:
> If the read of USB_PDPHY_RX_ACKNOWLEDGE_REG failed, then hdr_len and
> txbuf_len are uninitialized. It makes no sense to print message header
> and payload. It is also not safe to print uninitialized length of ram.
> 
> Signed-off-by: Rex Nie <rex.nie@jaguarmicro.com>

What commit id does this fix?

thanks,

greg k-h
[PATCH v2] usb: typec: qcom-pmic: init value of hdr_len/txbuf_len earlier
Posted by Rex Nie 3 weeks, 5 days ago
If the read of USB_PDPHY_RX_ACKNOWLEDGE_REG failed, then hdr_len and
txbuf_len are uninitialized. This commit stops to print uninitialized
value and misleading/false data.

Signed-off-by: Rex Nie <rex.nie@jaguarmicro.com>
---
 drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c b/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c
index 5b7f52b74a40..726423684bae 100644
--- a/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c
+++ b/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c
@@ -227,6 +227,10 @@ qcom_pmic_typec_pdphy_pd_transmit_payload(struct pmic_typec_pdphy *pmic_typec_pd
 
 	spin_lock_irqsave(&pmic_typec_pdphy->lock, flags);
 
+	hdr_len = sizeof(msg->header);
+	txbuf_len = pd_header_cnt_le(msg->header) * 4;
+	txsize_len = hdr_len + txbuf_len - 1;
+
 	ret = regmap_read(pmic_typec_pdphy->regmap,
 			  pmic_typec_pdphy->base + USB_PDPHY_RX_ACKNOWLEDGE_REG,
 			  &val);
@@ -244,10 +248,6 @@ qcom_pmic_typec_pdphy_pd_transmit_payload(struct pmic_typec_pdphy *pmic_typec_pd
 	if (ret)
 		goto done;
 
-	hdr_len = sizeof(msg->header);
-	txbuf_len = pd_header_cnt_le(msg->header) * 4;
-	txsize_len = hdr_len + txbuf_len - 1;
-
 	/* Write message header sizeof(u16) to USB_PDPHY_TX_BUFFER_HDR_REG */
 	ret = regmap_bulk_write(pmic_typec_pdphy->regmap,
 				pmic_typec_pdphy->base + USB_PDPHY_TX_BUFFER_HDR_REG,
-- 
2.17.1
Re: [PATCH v2] usb: typec: qcom-pmic: init value of hdr_len/txbuf_len earlier
Posted by Heikki Krogerus 3 weeks, 4 days ago
Hi,

On Wed, Oct 30, 2024 at 10:27:54AM +0800, Rex Nie wrote:
> If the read of USB_PDPHY_RX_ACKNOWLEDGE_REG failed, then hdr_len and
> txbuf_len are uninitialized. This commit stops to print uninitialized
> value and misleading/false data.
> 
> Signed-off-by: Rex Nie <rex.nie@jaguarmicro.com>
> ---

You need to include a changelog also for the patch itself here, after
that "---" separator. This patch is also still missing the Fixes tag.

You can read more about how to send the patches from the documentation:
https://www.kernel.org/doc/html/latest/process/submitting-patches.html

So please send v3 with those fixed. Don't forget to Cc the stable ml.:
https://www.kernel.org/doc/html/latest/process/submitting-patches.html#select-the-recipients-for-your-patch

thanks,

>  drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c b/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c
> index 5b7f52b74a40..726423684bae 100644
> --- a/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c
> +++ b/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c
> @@ -227,6 +227,10 @@ qcom_pmic_typec_pdphy_pd_transmit_payload(struct pmic_typec_pdphy *pmic_typec_pd
>  
>  	spin_lock_irqsave(&pmic_typec_pdphy->lock, flags);
>  
> +	hdr_len = sizeof(msg->header);
> +	txbuf_len = pd_header_cnt_le(msg->header) * 4;
> +	txsize_len = hdr_len + txbuf_len - 1;
> +
>  	ret = regmap_read(pmic_typec_pdphy->regmap,
>  			  pmic_typec_pdphy->base + USB_PDPHY_RX_ACKNOWLEDGE_REG,
>  			  &val);
> @@ -244,10 +248,6 @@ qcom_pmic_typec_pdphy_pd_transmit_payload(struct pmic_typec_pdphy *pmic_typec_pd
>  	if (ret)
>  		goto done;
>  
> -	hdr_len = sizeof(msg->header);
> -	txbuf_len = pd_header_cnt_le(msg->header) * 4;
> -	txsize_len = hdr_len + txbuf_len - 1;
> -
>  	/* Write message header sizeof(u16) to USB_PDPHY_TX_BUFFER_HDR_REG */
>  	ret = regmap_bulk_write(pmic_typec_pdphy->regmap,
>  				pmic_typec_pdphy->base + USB_PDPHY_TX_BUFFER_HDR_REG,
> -- 
> 2.17.1

-- 
heikki
[PATCH v4] usb: typec: qcom-pmic: init value of hdr_len/txbuf_len earlier
Posted by Rex Nie 3 weeks, 4 days ago
If the read of USB_PDPHY_RX_ACKNOWLEDGE_REG failed, then hdr_len and
txbuf_len are uninitialized. This commit stops to print uninitialized
value and misleading/false data.

Cc: stable@vger.kernel.org
Fixes: a4422ff22142 (" usb: typec: qcom: Add Qualcomm PMIC Type-C driver")
Signed-off-by: Rex Nie <rex.nie@jaguarmicro.com>
---
V2 -> V3:
- add changelog, add Fixes tag, add Cc stable ml. Thanks heikki
- Link to v2: https://lore.kernel.org/all/20241030022753.2045-1-rex.nie@jaguarmicro.com/
V1 -> V2:
- keep printout when data didn't transmit, thanks Bjorn, bod, greg k-h
- Links: https://lore.kernel.org/all/b177e736-e640-47ed-9f1e-ee65971dfc9c@linaro.org/
---
 drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c b/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c
index 5b7f52b74a40..726423684bae 100644
--- a/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c
+++ b/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c
@@ -227,6 +227,10 @@ qcom_pmic_typec_pdphy_pd_transmit_payload(struct pmic_typec_pdphy *pmic_typec_pd
 
 	spin_lock_irqsave(&pmic_typec_pdphy->lock, flags);
 
+	hdr_len = sizeof(msg->header);
+	txbuf_len = pd_header_cnt_le(msg->header) * 4;
+	txsize_len = hdr_len + txbuf_len - 1;
+
 	ret = regmap_read(pmic_typec_pdphy->regmap,
 			  pmic_typec_pdphy->base + USB_PDPHY_RX_ACKNOWLEDGE_REG,
 			  &val);
@@ -244,10 +248,6 @@ qcom_pmic_typec_pdphy_pd_transmit_payload(struct pmic_typec_pdphy *pmic_typec_pd
 	if (ret)
 		goto done;
 
-	hdr_len = sizeof(msg->header);
-	txbuf_len = pd_header_cnt_le(msg->header) * 4;
-	txsize_len = hdr_len + txbuf_len - 1;
-
 	/* Write message header sizeof(u16) to USB_PDPHY_TX_BUFFER_HDR_REG */
 	ret = regmap_bulk_write(pmic_typec_pdphy->regmap,
 				pmic_typec_pdphy->base + USB_PDPHY_TX_BUFFER_HDR_REG,
-- 
2.17.1
Re: [PATCH v4] usb: typec: qcom-pmic: init value of hdr_len/txbuf_len earlier
Posted by Bjorn Andersson 3 weeks, 2 days ago
On Wed, Oct 30, 2024 at 09:36:32PM GMT, Rex Nie wrote:
> If the read of USB_PDPHY_RX_ACKNOWLEDGE_REG failed, then hdr_len and
> txbuf_len are uninitialized. This commit stops to print uninitialized
> value and misleading/false data.
> 
> Cc: stable@vger.kernel.org
> Fixes: a4422ff22142 (" usb: typec: qcom: Add Qualcomm PMIC Type-C driver")
> Signed-off-by: Rex Nie <rex.nie@jaguarmicro.com>

Reviewed-by: Bjorn Andersson <andersson@kernel.org>

Nice job. Next time, please don't use In-Reply-To between patch
versions.

Regards,
Bjorn

> ---
> V2 -> V3:
> - add changelog, add Fixes tag, add Cc stable ml. Thanks heikki
> - Link to v2: https://lore.kernel.org/all/20241030022753.2045-1-rex.nie@jaguarmicro.com/
> V1 -> V2:
> - keep printout when data didn't transmit, thanks Bjorn, bod, greg k-h
> - Links: https://lore.kernel.org/all/b177e736-e640-47ed-9f1e-ee65971dfc9c@linaro.org/
> ---
>  drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c b/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c
> index 5b7f52b74a40..726423684bae 100644
> --- a/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c
> +++ b/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c
> @@ -227,6 +227,10 @@ qcom_pmic_typec_pdphy_pd_transmit_payload(struct pmic_typec_pdphy *pmic_typec_pd
>  
>  	spin_lock_irqsave(&pmic_typec_pdphy->lock, flags);
>  
> +	hdr_len = sizeof(msg->header);
> +	txbuf_len = pd_header_cnt_le(msg->header) * 4;
> +	txsize_len = hdr_len + txbuf_len - 1;
> +
>  	ret = regmap_read(pmic_typec_pdphy->regmap,
>  			  pmic_typec_pdphy->base + USB_PDPHY_RX_ACKNOWLEDGE_REG,
>  			  &val);
> @@ -244,10 +248,6 @@ qcom_pmic_typec_pdphy_pd_transmit_payload(struct pmic_typec_pdphy *pmic_typec_pd
>  	if (ret)
>  		goto done;
>  
> -	hdr_len = sizeof(msg->header);
> -	txbuf_len = pd_header_cnt_le(msg->header) * 4;
> -	txsize_len = hdr_len + txbuf_len - 1;
> -
>  	/* Write message header sizeof(u16) to USB_PDPHY_TX_BUFFER_HDR_REG */
>  	ret = regmap_bulk_write(pmic_typec_pdphy->regmap,
>  				pmic_typec_pdphy->base + USB_PDPHY_TX_BUFFER_HDR_REG,
> -- 
> 2.17.1
> 
>
Re: [PATCH v4] usb: typec: qcom-pmic: init value of hdr_len/txbuf_len earlier
Posted by Heikki Krogerus 3 weeks, 3 days ago
On Wed, Oct 30, 2024 at 09:36:32PM +0800, Rex Nie wrote:
> If the read of USB_PDPHY_RX_ACKNOWLEDGE_REG failed, then hdr_len and
> txbuf_len are uninitialized. This commit stops to print uninitialized
> value and misleading/false data.
> 
> Cc: stable@vger.kernel.org
> Fixes: a4422ff22142 (" usb: typec: qcom: Add Qualcomm PMIC Type-C driver")
> Signed-off-by: Rex Nie <rex.nie@jaguarmicro.com>

Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>

> ---
> V2 -> V3:
> - add changelog, add Fixes tag, add Cc stable ml. Thanks heikki
> - Link to v2: https://lore.kernel.org/all/20241030022753.2045-1-rex.nie@jaguarmicro.com/
> V1 -> V2:
> - keep printout when data didn't transmit, thanks Bjorn, bod, greg k-h
> - Links: https://lore.kernel.org/all/b177e736-e640-47ed-9f1e-ee65971dfc9c@linaro.org/
> ---
>  drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c b/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c
> index 5b7f52b74a40..726423684bae 100644
> --- a/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c
> +++ b/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c
> @@ -227,6 +227,10 @@ qcom_pmic_typec_pdphy_pd_transmit_payload(struct pmic_typec_pdphy *pmic_typec_pd
>  
>  	spin_lock_irqsave(&pmic_typec_pdphy->lock, flags);
>  
> +	hdr_len = sizeof(msg->header);
> +	txbuf_len = pd_header_cnt_le(msg->header) * 4;
> +	txsize_len = hdr_len + txbuf_len - 1;
> +
>  	ret = regmap_read(pmic_typec_pdphy->regmap,
>  			  pmic_typec_pdphy->base + USB_PDPHY_RX_ACKNOWLEDGE_REG,
>  			  &val);
> @@ -244,10 +248,6 @@ qcom_pmic_typec_pdphy_pd_transmit_payload(struct pmic_typec_pdphy *pmic_typec_pd
>  	if (ret)
>  		goto done;
>  
> -	hdr_len = sizeof(msg->header);
> -	txbuf_len = pd_header_cnt_le(msg->header) * 4;
> -	txsize_len = hdr_len + txbuf_len - 1;
> -
>  	/* Write message header sizeof(u16) to USB_PDPHY_TX_BUFFER_HDR_REG */
>  	ret = regmap_bulk_write(pmic_typec_pdphy->regmap,
>  				pmic_typec_pdphy->base + USB_PDPHY_TX_BUFFER_HDR_REG,
> -- 
> 2.17.1

-- 
heikki
[PATCH v3] usb: typec: qcom-pmic: init value of hdr_len/txbuf_len earlier
Posted by Rex Nie 3 weeks, 4 days ago
If the read of USB_PDPHY_RX_ACKNOWLEDGE_REG failed, then hdr_len and
txbuf_len are uninitialized. This commit stops to print uninitialized
value and misleading/false data.

---
V2 -> V3:
- add changelog, add Fixes tag, add Cc stable ml. Thanks heikki
- Link to v2: https://lore.kernel.org/all/20241030022753.2045-1-rex.nie@jaguarmicro.com/
V1 -> V2:
- keep printout when data didn't transmit, thanks Bjorn, bod, greg k-h
- Links: https://lore.kernel.org/all/b177e736-e640-47ed-9f1e-ee65971dfc9c@linaro.org/

Cc: stable@vger.kernel.org
Fixes: a4422ff22142 (" usb: typec: qcom: Add Qualcomm PMIC Type-C driver")
Signed-off-by: Rex Nie <rex.nie@jaguarmicro.com>
---
 drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c b/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c
index 5b7f52b74a40..726423684bae 100644
--- a/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c
+++ b/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c
@@ -227,6 +227,10 @@ qcom_pmic_typec_pdphy_pd_transmit_payload(struct pmic_typec_pdphy *pmic_typec_pd
 
 	spin_lock_irqsave(&pmic_typec_pdphy->lock, flags);
 
+	hdr_len = sizeof(msg->header);
+	txbuf_len = pd_header_cnt_le(msg->header) * 4;
+	txsize_len = hdr_len + txbuf_len - 1;
+
 	ret = regmap_read(pmic_typec_pdphy->regmap,
 			  pmic_typec_pdphy->base + USB_PDPHY_RX_ACKNOWLEDGE_REG,
 			  &val);
@@ -244,10 +248,6 @@ qcom_pmic_typec_pdphy_pd_transmit_payload(struct pmic_typec_pdphy *pmic_typec_pd
 	if (ret)
 		goto done;
 
-	hdr_len = sizeof(msg->header);
-	txbuf_len = pd_header_cnt_le(msg->header) * 4;
-	txsize_len = hdr_len + txbuf_len - 1;
-
 	/* Write message header sizeof(u16) to USB_PDPHY_TX_BUFFER_HDR_REG */
 	ret = regmap_bulk_write(pmic_typec_pdphy->regmap,
 				pmic_typec_pdphy->base + USB_PDPHY_TX_BUFFER_HDR_REG,
-- 
2.17.1
Re: [PATCH v3] usb: typec: qcom-pmic: init value of hdr_len/txbuf_len earlier
Posted by Heikki Krogerus 3 weeks, 4 days ago
On Wed, Oct 30, 2024 at 06:32:57PM +0800, Rex Nie wrote:
> If the read of USB_PDPHY_RX_ACKNOWLEDGE_REG failed, then hdr_len and
> txbuf_len are uninitialized. This commit stops to print uninitialized
> value and misleading/false data.
> 
> ---
> V2 -> V3:
> - add changelog, add Fixes tag, add Cc stable ml. Thanks heikki
> - Link to v2: https://lore.kernel.org/all/20241030022753.2045-1-rex.nie@jaguarmicro.com/
> V1 -> V2:
> - keep printout when data didn't transmit, thanks Bjorn, bod, greg k-h
> - Links: https://lore.kernel.org/all/b177e736-e640-47ed-9f1e-ee65971dfc9c@linaro.org/
> 
> Cc: stable@vger.kernel.org
> Fixes: a4422ff22142 (" usb: typec: qcom: Add Qualcomm PMIC Type-C driver")
> Signed-off-by: Rex Nie <rex.nie@jaguarmicro.com>

Sorry, but this is still broken.

Those tags need to come before the "---". Otherwise they will not
end-up into the actual commit when this patch is applied.

It should look something like this:

        usb: typec: qcom-pmic: init value of hdr_len/txbuf_len earlier

        If the read of USB_PDPHY_RX_ACKNOWLEDGE_REG failed, then hdr_len and
        txbuf_len are uninitialized. This commit stops to print uninitialized
        value and misleading/false data.

        Cc: stable@vger.kernel.org
        Fixes: a4422ff22142 (" usb: typec: qcom: Add Qualcomm PMIC Type-C driver")
        Signed-off-by: Rex Nie <rex.nie@jaguarmicro.com>
        ---
        V2 -> V3:
        - add changelog, add Fixes tag, add Cc stable ml. Thanks heikki
        - Link to v2: https://lore.kernel.org/all/20241030022753.2045-1-rex.nie@jaguarmicro.com/
        V1 -> V2:
        - keep printout when data didn't transmit, thanks Bjorn, bod, greg k-h
        - Links: https://lore.kernel.org/all/b177e736-e640-47ed-9f1e-ee65971dfc9c@linaro.org/

         drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c | 8 ++++----
         1 file changed, 4 insertions(+), 4 deletions(-)

        diff --git a/drivers/usb/typec...

thanks,

-- 
heikki
Re: [PATCH v3] usb: typec: qcom-pmic: init value of hdr_len/txbuf_len earlier
Posted by Bryan O'Donoghue 3 weeks, 4 days ago
On 30/10/2024 10:32, Rex Nie wrote:
> If the read of USB_PDPHY_RX_ACKNOWLEDGE_REG failed, then hdr_len and
> txbuf_len are uninitialized. This commit stops to print uninitialized
> value and misleading/false data.
> 
> ---
> V2 -> V3:
> - add changelog, add Fixes tag, add Cc stable ml. Thanks heikki
> - Link to v2: https://lore.kernel.org/all/20241030022753.2045-1-rex.nie@jaguarmicro.com/
> V1 -> V2:
> - keep printout when data didn't transmit, thanks Bjorn, bod, greg k-h
> - Links: https://lore.kernel.org/all/b177e736-e640-47ed-9f1e-ee65971dfc9c@linaro.org/
> 
> Cc: stable@vger.kernel.org
> Fixes: a4422ff22142 (" usb: typec: qcom: Add Qualcomm PMIC Type-C driver")
> Signed-off-by: Rex Nie <rex.nie@jaguarmicro.com>
> ---
>   drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c | 8 ++++----
>   1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c b/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c
> index 5b7f52b74a40..726423684bae 100644
> --- a/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c
> +++ b/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c
> @@ -227,6 +227,10 @@ qcom_pmic_typec_pdphy_pd_transmit_payload(struct pmic_typec_pdphy *pmic_typec_pd
>   
>   	spin_lock_irqsave(&pmic_typec_pdphy->lock, flags);
>   
> +	hdr_len = sizeof(msg->header);
> +	txbuf_len = pd_header_cnt_le(msg->header) * 4;
> +	txsize_len = hdr_len + txbuf_len - 1;
> +
>   	ret = regmap_read(pmic_typec_pdphy->regmap,
>   			  pmic_typec_pdphy->base + USB_PDPHY_RX_ACKNOWLEDGE_REG,
>   			  &val);
> @@ -244,10 +248,6 @@ qcom_pmic_typec_pdphy_pd_transmit_payload(struct pmic_typec_pdphy *pmic_typec_pd
>   	if (ret)
>   		goto done;
>   
> -	hdr_len = sizeof(msg->header);
> -	txbuf_len = pd_header_cnt_le(msg->header) * 4;
> -	txsize_len = hdr_len + txbuf_len - 1;
> -
>   	/* Write message header sizeof(u16) to USB_PDPHY_TX_BUFFER_HDR_REG */
>   	ret = regmap_bulk_write(pmic_typec_pdphy->regmap,
>   				pmic_typec_pdphy->base + USB_PDPHY_TX_BUFFER_HDR_REG,
Acked-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>