mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2] mtd: ubi: fix NVMEM over UBI volumes on 32-bit systems
@ 2024-02-28  0:46 Daniel Golle
  2024-02-28  1:45 ` Zhihao Cheng
  0 siblings, 1 reply; 5+ messages in thread
From: Daniel Golle @ 2024-02-28  0:46 UTC (permalink / raw)
  To: Richard Weinberger, Zhihao Cheng, Miquel Raynal,
	Vignesh Raghavendra, Daniel Golle, linux-mtd, linux-kernel

A compiler warning related to sizeof(int) != 8 when calling do_div()
is triggered when building on 32-bit platforms.
Address this by using integer types having a well-defined size.

Fixes: 3ce485803da1 ("mtd: ubi: provide NVMEM layer over UBI volumes")
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
---
v2: use size_t for 'bytes_left' variable to match parameter type

 drivers/mtd/ubi/nvmem.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/mtd/ubi/nvmem.c b/drivers/mtd/ubi/nvmem.c
index b7a93c495d172..e68b8589c4279 100644
--- a/drivers/mtd/ubi/nvmem.c
+++ b/drivers/mtd/ubi/nvmem.c
@@ -23,9 +23,12 @@ struct ubi_nvmem {
 static int ubi_nvmem_reg_read(void *priv, unsigned int from,
 			      void *val, size_t bytes)
 {
-	int err = 0, lnum = from, offs, bytes_left = bytes, to_read;
 	struct ubi_nvmem *unv = priv;
 	struct ubi_volume_desc *desc;
+	size_t bytes_left = bytes;
+	uint32_t offs, to_read;
+	uint64_t lnum = from;
+	int err = 0;
 
 	desc = ubi_open_volume(unv->ubi_num, unv->vol_id, UBI_READONLY);
 	if (IS_ERR(desc))
-- 
2.44.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] mtd: ubi: fix NVMEM over UBI volumes on 32-bit systems
  2024-02-28  0:46 [PATCH v2] mtd: ubi: fix NVMEM over UBI volumes on 32-bit systems Daniel Golle
@ 2024-02-28  1:45 ` Zhihao Cheng
  2024-03-07  9:17   ` Dan Carpenter
  0 siblings, 1 reply; 5+ messages in thread
From: Zhihao Cheng @ 2024-02-28  1:45 UTC (permalink / raw)
  To: Daniel Golle, Richard Weinberger, Miquel Raynal,
	Vignesh Raghavendra, linux-mtd, linux-kernel

在 2024/2/28 8:46, Daniel Golle 写道:
> A compiler warning related to sizeof(int) != 8 when calling do_div()
> is triggered when building on 32-bit platforms.
> Address this by using integer types having a well-defined size.
> 
> Fixes: 3ce485803da1 ("mtd: ubi: provide NVMEM layer over UBI volumes")
> Signed-off-by: Daniel Golle <daniel@makrotopia.org>
> ---
> v2: use size_t for 'bytes_left' variable to match parameter type
> 
>   drivers/mtd/ubi/nvmem.c | 5 ++++-
>   1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/mtd/ubi/nvmem.c b/drivers/mtd/ubi/nvmem.c
> index b7a93c495d172..e68b8589c4279 100644
> --- a/drivers/mtd/ubi/nvmem.c
> +++ b/drivers/mtd/ubi/nvmem.c
> @@ -23,9 +23,12 @@ struct ubi_nvmem {
>   static int ubi_nvmem_reg_read(void *priv, unsigned int from,
>   			      void *val, size_t bytes)
>   {
> -	int err = 0, lnum = from, offs, bytes_left = bytes, to_read;
>   	struct ubi_nvmem *unv = priv;
>   	struct ubi_volume_desc *desc;
> +	size_t bytes_left = bytes;
> +	uint32_t offs, to_read;
There still exist a type truncation assignment 'to_read = bytes_left' 
below, although it's safe in logic.
> +	uint64_t lnum = from;
> +	int err = 0;
>   
>   	desc = ubi_open_volume(unv->ubi_num, unv->vol_id, UBI_READONLY);
>   	if (IS_ERR(desc))
> 


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] mtd: ubi: fix NVMEM over UBI volumes on 32-bit systems
  2024-02-28  1:45 ` Zhihao Cheng
@ 2024-03-07  9:17   ` Dan Carpenter
  2024-03-07 11:42     ` Daniel Golle
  0 siblings, 1 reply; 5+ messages in thread
From: Dan Carpenter @ 2024-03-07  9:17 UTC (permalink / raw)
  To: Zhihao Cheng
  Cc: Daniel Golle, Richard Weinberger, Miquel Raynal,
	Vignesh Raghavendra, linux-mtd, linux-kernel, Guenter Roeck,
	Daniel Diaz, Naresh Kamboju

On Wed, Feb 28, 2024 at 09:45:13AM +0800, Zhihao Cheng wrote:
> 在 2024/2/28 8:46, Daniel Golle 写道:
> > A compiler warning related to sizeof(int) != 8 when calling do_div()
> > is triggered when building on 32-bit platforms.
> > Address this by using integer types having a well-defined size.
> > 
> > Fixes: 3ce485803da1 ("mtd: ubi: provide NVMEM layer over UBI volumes")
> > Signed-off-by: Daniel Golle <daniel@makrotopia.org>
> > ---
> > v2: use size_t for 'bytes_left' variable to match parameter type
> > 
> >   drivers/mtd/ubi/nvmem.c | 5 ++++-
> >   1 file changed, 4 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/mtd/ubi/nvmem.c b/drivers/mtd/ubi/nvmem.c
> > index b7a93c495d172..e68b8589c4279 100644
> > --- a/drivers/mtd/ubi/nvmem.c
> > +++ b/drivers/mtd/ubi/nvmem.c
> > @@ -23,9 +23,12 @@ struct ubi_nvmem {
> >   static int ubi_nvmem_reg_read(void *priv, unsigned int from,
> >   			      void *val, size_t bytes)
> >   {
> > -	int err = 0, lnum = from, offs, bytes_left = bytes, to_read;
> >   	struct ubi_nvmem *unv = priv;
> >   	struct ubi_volume_desc *desc;
> > +	size_t bytes_left = bytes;
> > +	uint32_t offs, to_read;
> There still exist a type truncation assignment 'to_read = bytes_left' below,
> although it's safe in logic.

Yeah.  As you say, from looking at the logic we know it's safe.

    41                  if (to_read > bytes_left)
    42                          to_read = bytes_left;

Obviously the new value is smaller than the original, so it must fit
within a u32 range...

This bug has been breaking the build since Dec 19.  It's fine if you're
able to manually create your own .configs to work around build breakage.
But if you're doing automated testing at scale then it's a show stopper.
Could we please fix it.

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] mtd: ubi: fix NVMEM over UBI volumes on 32-bit systems
  2024-03-07  9:17   ` Dan Carpenter
@ 2024-03-07 11:42     ` Daniel Golle
  2024-03-07 12:03       ` Dan Carpenter
  0 siblings, 1 reply; 5+ messages in thread
From: Daniel Golle @ 2024-03-07 11:42 UTC (permalink / raw)
  To: linux-mtd, Dan Carpenter, Zhihao Cheng
  Cc: Richard Weinberger, Miquel Raynal, Vignesh Raghavendra,
	linux-kernel, Guenter Roeck, Daniel Diaz, Naresh Kamboju



On 7 March 2024 09:17:45 UTC, Dan Carpenter <dan.carpenter@linaro.org> wrote:
>On Wed, Feb 28, 2024 at 09:45:13AM +0800, Zhihao Cheng wrote:
>> 在 2024/2/28 8:46, Daniel Golle 写道:
>> > A compiler warning related to sizeof(int) != 8 when calling do_div()
>> > is triggered when building on 32-bit platforms.
>> > Address this by using integer types having a well-defined size.
>> > 
>> > Fixes: 3ce485803da1 ("mtd: ubi: provide NVMEM layer over UBI volumes")
>> > Signed-off-by: Daniel Golle <daniel@makrotopia.org>
>> > ---
>> > v2: use size_t for 'bytes_left' variable to match parameter type
>> > 
>> >   drivers/mtd/ubi/nvmem.c | 5 ++++-
>> >   1 file changed, 4 insertions(+), 1 deletion(-)
>> > 
>> > diff --git a/drivers/mtd/ubi/nvmem.c b/drivers/mtd/ubi/nvmem.c
>> > index b7a93c495d172..e68b8589c4279 100644
>> > --- a/drivers/mtd/ubi/nvmem.c
>> > +++ b/drivers/mtd/ubi/nvmem.c
>> > @@ -23,9 +23,12 @@ struct ubi_nvmem {
>> >   static int ubi_nvmem_reg_read(void *priv, unsigned int from,
>> >   			      void *val, size_t bytes)
>> >   {
>> > -	int err = 0, lnum = from, offs, bytes_left = bytes, to_read;
>> >   	struct ubi_nvmem *unv = priv;
>> >   	struct ubi_volume_desc *desc;
>> > +	size_t bytes_left = bytes;
>> > +	uint32_t offs, to_read;
>> There still exist a type truncation assignment 'to_read = bytes_left' below,
>> although it's safe in logic.
>
>Yeah.  As you say, from looking at the logic we know it's safe.
>
>    41                  if (to_read > bytes_left)
>    42                          to_read = bytes_left;
>
>Obviously the new value is smaller than the original, so it must fit
>within a u32 range...


I've sent v3 of this fix which should be finally be warning free now.

https://patchwork.ozlabs.org/project/linux-mtd/patch/ff29447dcee834c17e4e1e99725b9454c90136ca.1709178325.git.daniel@makrotopia.org/

>
>This bug has been breaking the build since Dec 19.  

I have a hard time believing that as the offending commit was only applied on Feb 25.

https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/?id=3ce485803da1b79b2692b6d0c2792829292ad838

> It's fine if you're
>able to manually create your own .configs to work around build breakage.
>But if you're doing automated testing at scale then it's a show stopper.
>Could we please fix it.
>
>regards,
>dan carpenter
>
>
>______________________________________________________
>Linux MTD discussion mailing list
>http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] mtd: ubi: fix NVMEM over UBI volumes on 32-bit systems
  2024-03-07 11:42     ` Daniel Golle
@ 2024-03-07 12:03       ` Dan Carpenter
  0 siblings, 0 replies; 5+ messages in thread
From: Dan Carpenter @ 2024-03-07 12:03 UTC (permalink / raw)
  To: Daniel Golle
  Cc: linux-mtd, Zhihao Cheng, Richard Weinberger, Miquel Raynal,
	Vignesh Raghavendra, linux-kernel, Guenter Roeck, Daniel Diaz,
	Naresh Kamboju

On Thu, Mar 07, 2024 at 11:42:12AM +0000, Daniel Golle wrote:
> 
> 
> On 7 March 2024 09:17:45 UTC, Dan Carpenter <dan.carpenter@linaro.org> wrote:
> >On Wed, Feb 28, 2024 at 09:45:13AM +0800, Zhihao Cheng wrote:
> >> 在 2024/2/28 8:46, Daniel Golle 写道:
> >> > A compiler warning related to sizeof(int) != 8 when calling do_div()
> >> > is triggered when building on 32-bit platforms.
> >> > Address this by using integer types having a well-defined size.
> >> > 
> >> > Fixes: 3ce485803da1 ("mtd: ubi: provide NVMEM layer over UBI volumes")
> >> > Signed-off-by: Daniel Golle <daniel@makrotopia.org>
> >> > ---
> >> > v2: use size_t for 'bytes_left' variable to match parameter type
> >> > 
> >> >   drivers/mtd/ubi/nvmem.c | 5 ++++-
> >> >   1 file changed, 4 insertions(+), 1 deletion(-)
> >> > 
> >> > diff --git a/drivers/mtd/ubi/nvmem.c b/drivers/mtd/ubi/nvmem.c
> >> > index b7a93c495d172..e68b8589c4279 100644
> >> > --- a/drivers/mtd/ubi/nvmem.c
> >> > +++ b/drivers/mtd/ubi/nvmem.c
> >> > @@ -23,9 +23,12 @@ struct ubi_nvmem {
> >> >   static int ubi_nvmem_reg_read(void *priv, unsigned int from,
> >> >   			      void *val, size_t bytes)
> >> >   {
> >> > -	int err = 0, lnum = from, offs, bytes_left = bytes, to_read;
> >> >   	struct ubi_nvmem *unv = priv;
> >> >   	struct ubi_volume_desc *desc;
> >> > +	size_t bytes_left = bytes;
> >> > +	uint32_t offs, to_read;
> >> There still exist a type truncation assignment 'to_read = bytes_left' below,
> >> although it's safe in logic.
> >
> >Yeah.  As you say, from looking at the logic we know it's safe.
> >
> >    41                  if (to_read > bytes_left)
> >    42                          to_read = bytes_left;
> >
> >Obviously the new value is smaller than the original, so it must fit
> >within a u32 range...
> 
> 
> I've sent v3 of this fix which should be finally be warning free now.
> 
> https://patchwork.ozlabs.org/project/linux-mtd/patch/ff29447dcee834c17e4e1e99725b9454c90136ca.1709178325.git.daniel@makrotopia.org/
> 

Thanks!

> >
> >This bug has been breaking the build since Dec 19.  
> 
> I have a hard time believing that as the offending commit was only applied on Feb 25.
> 
> https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/?id=3ce485803da1b79b2692b6d0c2792829292ad838
> 

Ah...  Okay.  I was looking at the author date.  Not the merge date.  My
bad.

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-03-07 12:04 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-28  0:46 [PATCH v2] mtd: ubi: fix NVMEM over UBI volumes on 32-bit systems Daniel Golle
2024-02-28  1:45 ` Zhihao Cheng
2024-03-07  9:17   ` Dan Carpenter
2024-03-07 11:42     ` Daniel Golle
2024-03-07 12:03       ` Dan Carpenter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®