2018-11-15 05:08:33

by Huijin Park

[permalink] [raw]
Subject: [PATCH v2] mtd: change len type from signed to unsigned type

From: "huijin.park" <[email protected]>

This patch casts the "len" parameter to an unsigned int.
The callers of erase_write() pass the "len" parameter as unsigned int.

Signed-off-by: huijin.park <[email protected]>
---
drivers/mtd/mtdblock.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mtd/mtdblock.c b/drivers/mtd/mtdblock.c
index a5b1933..b2d5ed1 100644
--- a/drivers/mtd/mtdblock.c
+++ b/drivers/mtd/mtdblock.c
@@ -56,7 +56,7 @@ struct mtdblk_dev {
*/

static int erase_write (struct mtd_info *mtd, unsigned long pos,
- int len, const char *buf)
+ unsigned int len, const char *buf)
{
struct erase_info erase;
size_t retlen;
--
1.7.9.5



2018-11-15 09:31:41

by Miquel Raynal

[permalink] [raw]
Subject: Re: [PATCH v2] mtd: change len type from signed to unsigned type

Hi Huijin,

Huijin Park <[email protected]> wrote on Thu, 15 Nov 2018
00:07:10 -0500:

> From: "huijin.park" <[email protected]>
>
> This patch casts the "len" parameter to an unsigned int.
> The callers of erase_write() pass the "len" parameter as unsigned int.

Indeed. Perhaps it is worth backporting this patch to a stable releases?

>
> Signed-off-by: huijin.park <[email protected]>
> ---
> drivers/mtd/mtdblock.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/mtd/mtdblock.c b/drivers/mtd/mtdblock.c
> index a5b1933..b2d5ed1 100644
> --- a/drivers/mtd/mtdblock.c
> +++ b/drivers/mtd/mtdblock.c
> @@ -56,7 +56,7 @@ struct mtdblk_dev {
> */
>
> static int erase_write (struct mtd_info *mtd, unsigned long pos,
> - int len, const char *buf)
> + unsigned int len, const char *buf)
> {
> struct erase_info erase;
> size_t retlen;

Reviewed-by: Miquel Raynal <[email protected]>


Thanks,
Miquèl

2018-11-15 13:35:22

by Boris Brezillon

[permalink] [raw]
Subject: Re: [PATCH v2] mtd: change len type from signed to unsigned type

On Thu, 15 Nov 2018 00:07:10 -0500
Huijin Park <[email protected]> wrote:

> From: "huijin.park" <[email protected]>
>
> This patch casts the "len" parameter to an unsigned int.

Hm, that's not really what this patch actually. Actually it avoids the
cast from an int to an unsigned int.

> The callers of erase_write() pass the "len" parameter as unsigned int.

That's the important part here. Callers of erase_write() always pass an
unsigned int, so what you're trying to do here is avoid a cast to an
int.

>
> Signed-off-by: huijin.park <[email protected]>
> ---

You should have a changelog here.

> drivers/mtd/mtdblock.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/mtd/mtdblock.c b/drivers/mtd/mtdblock.c
> index a5b1933..b2d5ed1 100644
> --- a/drivers/mtd/mtdblock.c
> +++ b/drivers/mtd/mtdblock.c
> @@ -56,7 +56,7 @@ struct mtdblk_dev {
> */
>
> static int erase_write (struct mtd_info *mtd, unsigned long pos,
> - int len, const char *buf)
> + unsigned int len, const char *buf)
> {
> struct erase_info erase;
> size_t retlen;


2018-11-28 14:52:16

by Huijin Park

[permalink] [raw]
Subject: Re: [PATCH v2] mtd: change len type from signed to unsigned type

Hi Miquèl,

On Thu, Nov 15, 2018 at 6:29 PM Miquel Raynal <[email protected]> wrote:
>
> Hi Huijin,
>
> Huijin Park <[email protected]> wrote on Thu, 15 Nov 2018
> 00:07:10 -0500:
>
> > From: "huijin.park" <[email protected]>
> >
> > This patch casts the "len" parameter to an unsigned int.
> > The callers of erase_write() pass the "len" parameter as unsigned int.
>
> Indeed. Perhaps it is worth backporting this patch to a stable releases?
>

It doesn't need backporting.
Because this patch is for enforcing code correctness.

> >
> > Signed-off-by: huijin.park <[email protected]>
> > ---
> > drivers/mtd/mtdblock.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/mtd/mtdblock.c b/drivers/mtd/mtdblock.c
> > index a5b1933..b2d5ed1 100644
> > --- a/drivers/mtd/mtdblock.c
> > +++ b/drivers/mtd/mtdblock.c
> > @@ -56,7 +56,7 @@ struct mtdblk_dev {
> > */
> >
> > static int erase_write (struct mtd_info *mtd, unsigned long pos,
> > - int len, const char *buf)
> > + unsigned int len, const char *buf)
> > {
> > struct erase_info erase;
> > size_t retlen;
>
> Reviewed-by: Miquel Raynal <[email protected]>
>
>
> Thanks,
> Miquèl

Thanks,
Huijin