diff mbox series

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

Message ID 20241029021823.1978-1-rex.nie@jaguarmicro.com
State New
Headers show
Series usb: typec: qcom-pmic: fix uninitialized value hdr_len and txbuf_len | expand

Commit Message

Rex Nie Oct. 29, 2024, 2:18 a.m. UTC
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(-)

Comments

Bryan O'Donoghue Oct. 29, 2024, 3:38 p.m. UTC | #1
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
Heikki Krogerus Oct. 30, 2024, 8:39 a.m. UTC | #2
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
Rex Nie Oct. 30, 2024, 10:35 a.m. UTC | #3
HI heikki,
	Thanks. I will send patch v3 soon.
BRs
Rex

> -----邮件原件-----
> 发件人: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> 发送时间: 2024年10月30日 16:39
> 收件人: Rex Nie <rex.nie@jaguarmicro.com>
> 抄送: bryan.odonoghue@linaro.org; gregkh@linuxfoundation.org;
> linux-arm-msm@vger.kernel.org; linux-usb@vger.kernel.org;
> linux-kernel@vger.kernel.org; Angus Chen <angus.chen@jaguarmicro.com>
> 主题: Re: [PATCH v2] usb: typec: qcom-pmic: init value of hdr_len/txbuf_len
> earlier
> 
> External Mail: This email originated from OUTSIDE of the organization!
> Do not click links, open attachments or provide ANY information unless you
> recognize the sender and know the content is safe.
> 
> 
> 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#s
> elect-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
diff mbox series

Patch

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;