mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] mtd: ubi: fix NVMEM over UBI volumes on 32-bit systems
@ 2024-02-26 18:23 Daniel Golle
  2024-02-27  2:23 ` Zhihao Cheng
  0 siblings, 1 reply; 3+ messages in thread
From: Daniel Golle @ 2024-02-26 18:23 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 where
appropriate.

Fixes: 3ce485803da1 ("mtd: ubi: provide NVMEM layer over UBI volumes")
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
---
 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..5820a170d2512 100644
--- a/drivers/mtd/ubi/nvmem.c
+++ b/drivers/mtd/ubi/nvmem.c
@@ -23,14 +23,17 @@ 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;
+	uint32_t bytes_left, offs, to_read;
 	struct ubi_nvmem *unv = priv;
 	struct ubi_volume_desc *desc;
+	uint64_t lnum = from;
+	int err = 0;
 
 	desc = ubi_open_volume(unv->ubi_num, unv->vol_id, UBI_READONLY);
 	if (IS_ERR(desc))
 		return PTR_ERR(desc);
 
+	bytes_left = bytes;
 	offs = do_div(lnum, unv->usable_leb_size);
 	while (bytes_left) {
 		to_read = unv->usable_leb_size - offs;
-- 
2.44.0


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

* Re: [PATCH] mtd: ubi: fix NVMEM over UBI volumes on 32-bit systems
  2024-02-26 18:23 [PATCH] mtd: ubi: fix NVMEM over UBI volumes on 32-bit systems Daniel Golle
@ 2024-02-27  2:23 ` Zhihao Cheng
  2024-02-27 12:57   ` Daniel Golle
  0 siblings, 1 reply; 3+ messages in thread
From: Zhihao Cheng @ 2024-02-27  2:23 UTC (permalink / raw)
  To: Daniel Golle, Richard Weinberger, Miquel Raynal,
	Vignesh Raghavendra, linux-mtd, linux-kernel

在 2024/2/27 2:23, 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 where
> appropriate.
> 
> Fixes: 3ce485803da1 ("mtd: ubi: provide NVMEM layer over UBI volumes")
> Signed-off-by: Daniel Golle <daniel@makrotopia.org>
> ---
>   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..5820a170d2512 100644
> --- a/drivers/mtd/ubi/nvmem.c
> +++ b/drivers/mtd/ubi/nvmem.c
> @@ -23,14 +23,17 @@ 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;
> +	uint32_t bytes_left, offs, to_read;
>   	struct ubi_nvmem *unv = priv;
>   	struct ubi_volume_desc *desc;
> +	uint64_t lnum = from;
> +	int err = 0;
>   
>   	desc = ubi_open_volume(unv->ubi_num, unv->vol_id, UBI_READONLY);
>   	if (IS_ERR(desc))
>   		return PTR_ERR(desc);
>   
> +	bytes_left = bytes;
The 'bytes' is a size_t type, which has 64 bits on 64-bit platforms. 
This assignment will lead a type truncation, so should we add a explicit 
type conversion here to avoid compiler warning?
>   	offs = do_div(lnum, unv->usable_leb_size);
>   	while (bytes_left) {
>   		to_read = unv->usable_leb_size - offs;
> 


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

* Re: [PATCH] mtd: ubi: fix NVMEM over UBI volumes on 32-bit systems
  2024-02-27  2:23 ` Zhihao Cheng
@ 2024-02-27 12:57   ` Daniel Golle
  0 siblings, 0 replies; 3+ messages in thread
From: Daniel Golle @ 2024-02-27 12:57 UTC (permalink / raw)
  To: Zhihao Cheng
  Cc: Richard Weinberger, Miquel Raynal, Vignesh Raghavendra,
	linux-mtd, linux-kernel

On Tue, Feb 27, 2024 at 10:23:17AM +0800, Zhihao Cheng wrote:
> 在 2024/2/27 2:23, 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 where
> > appropriate.
> > 
> > Fixes: 3ce485803da1 ("mtd: ubi: provide NVMEM layer over UBI volumes")
> > Signed-off-by: Daniel Golle <daniel@makrotopia.org>
> > ---
> >   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..5820a170d2512 100644
> > --- a/drivers/mtd/ubi/nvmem.c
> > +++ b/drivers/mtd/ubi/nvmem.c
> > @@ -23,14 +23,17 @@ 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;
> > +	uint32_t bytes_left, offs, to_read;
> >   	struct ubi_nvmem *unv = priv;
> >   	struct ubi_volume_desc *desc;
> > +	uint64_t lnum = from;
> > +	int err = 0;
> >   	desc = ubi_open_volume(unv->ubi_num, unv->vol_id, UBI_READONLY);
> >   	if (IS_ERR(desc))
> >   		return PTR_ERR(desc);
> > +	bytes_left = bytes;
> The 'bytes' is a size_t type, which has 64 bits on 64-bit platforms. This
> assignment will lead a type truncation, so should we add a explicit type
> conversion here to avoid compiler warning?

Oh right. I reckon the best is to declare 'bytes' as 'size_t' type as well
then. I will send v2 with that change shortly.


> >   	offs = do_div(lnum, unv->usable_leb_size);
> >   	while (bytes_left) {
> >   		to_read = unv->usable_leb_size - offs;
> > 
> 
> 
> ______________________________________________________
> Linux MTD discussion mailing list
> http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

end of thread, other threads:[~2024-02-27 12:57 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-26 18:23 [PATCH] mtd: ubi: fix NVMEM over UBI volumes on 32-bit systems Daniel Golle
2024-02-27  2:23 ` Zhihao Cheng
2024-02-27 12:57   ` Daniel Golle

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®