diff mbox series

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

Message ID 20241030022753.2045-1-rex.nie@jaguarmicro.com
State Accepted
Commit 029778a4fd2c90c2e76a902b797c2348a722f1b8
Headers show
Series [v2] usb: typec: qcom-pmic: init value of hdr_len/txbuf_len earlier | expand

Commit Message

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

Comments

Bjorn Andersson Nov. 1, 2024, 3:45 p.m. UTC | #1
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
> 
>
Rex Nie Nov. 2, 2024, 12:27 p.m. UTC | #2
Bjorn,
	Ok, get it, Thanks.
BRs
Rex
> -----邮件原件-----
> 发件人: Bjorn Andersson <andersson@kernel.org>
> 发送时间: 2024年11月1日 23:45
> 收件人: Rex Nie <rex.nie@jaguarmicro.com>
> 抄送: bryan.odonoghue@linaro.org; heikki.krogerus@linux.intel.com;
> gregkh@linuxfoundation.org; linux@roeck-us.net; caleb.connolly@linaro.org;
> linux-arm-msm@vger.kernel.org; linux-usb@vger.kernel.org;
> linux-kernel@vger.kernel.org; Angus Chen <angus.chen@jaguarmicro.com>;
> stable@vger.kernel.org
> 主题: Re: [PATCH v4] 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.
> 
> 
> 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@linar
> > o.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
> >
> >
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..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,