Discussion:
[PATCH] mtd: change len type from signed to unsigned type
Huijin Park
2018-08-23 08:43:39 UTC
Permalink
From: "huijin.park" <***@samsung.com>

assign of a signed value which has type 'int' to a variable of
a bigger unsigned integer type 'uint64_t'.
this is ok most of the time, but can lead to unexpectedly large
resulting value if the original signed value is negative.
in addtion, the callers of the erase_write() pass the len parameter
as unsigned type.

Signed-off-by: huijin.park <***@samsung.com>
---
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
Boris Brezillon
2018-10-31 14:02:25 UTC
Permalink
Hi Huijin,

On Thu, 23 Aug 2018 04:43:39 -0400
Post by Huijin Park
assign of a signed value which has type 'int' to a variable of
a bigger unsigned integer type 'uint64_t'.
Why are you mentioning u64? AFAICT, the len passed to erase_write() is
always an unsigned int.
Post by Huijin Park
this is ok most of the time, but can lead to unexpectedly large
resulting value if the original signed value is negative.
in addtion, the callers of the erase_write() pass the len parameter
^In addition,
Post by Huijin Park
as unsigned type.
---
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)
The diff looks good, but the commit message is not clear at all. Can
you reword it?

Thanks,

Boris
Post by Huijin Park
{
struct erase_info erase;
size_t retlen;
Huijin Park
2018-11-12 16:27:05 UTC
Permalink
Hi Boris,

On Wed, Oct 31, 2018 at 11:02 PM Boris Brezillon
Post by Boris Brezillon
Hi Huijin,
On Thu, 23 Aug 2018 04:43:39 -0400
Post by Huijin Park
assign of a signed value which has type 'int' to a variable of
a bigger unsigned integer type 'uint64_t'.
Why are you mentioning u64? AFAICT, the len passed to erase_write() is
always an unsigned int.
It's my mistake.
Messages about u64 are not related to this patch.
Post by Boris Brezillon
Post by Huijin Park
this is ok most of the time, but can lead to unexpectedly large
resulting value if the original signed value is negative.
in addtion, the callers of the erase_write() pass the len parameter
^In addition,
Post by Huijin Park
as unsigned type.
---
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)
The diff looks good, but the commit message is not clear at all. Can
you reword it?
Thanks,
Boris
Post by Huijin Park
{
struct erase_info erase;
size_t retlen;
I will send again patch after reword the commit message.

Thanks & best regards,

Huijin
Huijin Park
2018-11-13 05:16:41 UTC
Permalink
From: "huijin.park" <***@samsung.com>

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 <***@samsung.com>
---
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
Loading...