All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/3] nvram: at24c: fix problems related to "rom-size"
@ 2018-03-19 21:30 ` Wolfram Sang
  0 siblings, 0 replies; 20+ messages in thread
From: Wolfram Sang @ 2018-03-19 21:30 UTC (permalink / raw)
  To: qemu-devel; +Cc: Philippe Mathieu-Daudé, linux-renesas-soc, Wolfram Sang

I used this driver as a template for a custom one. While hacking on my own, I
noticed some problems in this driver, too. This series fixes the first set of
them, related to the "rom-size" parameter. It fixes a segfault.

I think the first patch is clearly suitable for stable. I think the second one,
too, but not as clearly. The third one is a cleanup and not for stable. Still,
I am open for opinions about these thoughts.

Thanks,

   Wolfram

Changes since v1:

* reordered patches according to significance for stable
* use AT24C_ROMSIZE_DEFAULT instead of magic value
* patch 3 doesn't improve the ERR macro anymore but replaces
  it completely with error_report().


Wolfram Sang (3):
  nvram: at24c: prevent segfault by checking "rom-size"
  nvram: at24c: use a sane default for "rom-size"
  nvram: at24c: use standard error reporting

 hw/nvram/eeprom_at24c.c | 25 ++++++++++++++-----------
 1 file changed, 14 insertions(+), 11 deletions(-)

-- 
2.11.0

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

* [Qemu-devel] [PATCH v2 0/3] nvram: at24c: fix problems related to "rom-size"
@ 2018-03-19 21:30 ` Wolfram Sang
  0 siblings, 0 replies; 20+ messages in thread
From: Wolfram Sang @ 2018-03-19 21:30 UTC (permalink / raw)
  To: qemu-devel; +Cc: Philippe Mathieu-Daudé, linux-renesas-soc, Wolfram Sang

I used this driver as a template for a custom one. While hacking on my own, I
noticed some problems in this driver, too. This series fixes the first set of
them, related to the "rom-size" parameter. It fixes a segfault.

I think the first patch is clearly suitable for stable. I think the second one,
too, but not as clearly. The third one is a cleanup and not for stable. Still,
I am open for opinions about these thoughts.

Thanks,

   Wolfram

Changes since v1:

* reordered patches according to significance for stable
* use AT24C_ROMSIZE_DEFAULT instead of magic value
* patch 3 doesn't improve the ERR macro anymore but replaces
  it completely with error_report().


Wolfram Sang (3):
  nvram: at24c: prevent segfault by checking "rom-size"
  nvram: at24c: use a sane default for "rom-size"
  nvram: at24c: use standard error reporting

 hw/nvram/eeprom_at24c.c | 25 ++++++++++++++-----------
 1 file changed, 14 insertions(+), 11 deletions(-)

-- 
2.11.0

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

* [PATCH v2 1/3] nvram: at24c: prevent segfault by checking "rom-size"
  2018-03-19 21:30 ` [Qemu-devel] " Wolfram Sang
@ 2018-03-19 21:30   ` Wolfram Sang
  -1 siblings, 0 replies; 20+ messages in thread
From: Wolfram Sang @ 2018-03-19 21:30 UTC (permalink / raw)
  To: qemu-devel; +Cc: Philippe Mathieu-Daudé, linux-renesas-soc, Wolfram Sang

The value for "rom-size" is used as a divisor, so it must not be 0 or it
will segfault. A size of 0 wouldn't make sense anyhow.

Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
---
 hw/nvram/eeprom_at24c.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/hw/nvram/eeprom_at24c.c b/hw/nvram/eeprom_at24c.c
index 22183f5360..ccf78b25e4 100644
--- a/hw/nvram/eeprom_at24c.c
+++ b/hw/nvram/eeprom_at24c.c
@@ -121,6 +121,11 @@ int at24c_eeprom_init(I2CSlave *i2c)
 {
     EEPROMState *ee = AT24C_EE(i2c);
 
+    if (!ee->rsize) {
+        ERR("rom-size not allowed to be 0\n");
+        exit(1);
+    }
+
     ee->mem = g_malloc0(ee->rsize);
 
     if (ee->blk) {
-- 
2.11.0

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

* [Qemu-devel] [PATCH v2 1/3] nvram: at24c: prevent segfault by checking "rom-size"
@ 2018-03-19 21:30   ` Wolfram Sang
  0 siblings, 0 replies; 20+ messages in thread
From: Wolfram Sang @ 2018-03-19 21:30 UTC (permalink / raw)
  To: qemu-devel; +Cc: Philippe Mathieu-Daudé, linux-renesas-soc, Wolfram Sang

The value for "rom-size" is used as a divisor, so it must not be 0 or it
will segfault. A size of 0 wouldn't make sense anyhow.

Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
---
 hw/nvram/eeprom_at24c.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/hw/nvram/eeprom_at24c.c b/hw/nvram/eeprom_at24c.c
index 22183f5360..ccf78b25e4 100644
--- a/hw/nvram/eeprom_at24c.c
+++ b/hw/nvram/eeprom_at24c.c
@@ -121,6 +121,11 @@ int at24c_eeprom_init(I2CSlave *i2c)
 {
     EEPROMState *ee = AT24C_EE(i2c);
 
+    if (!ee->rsize) {
+        ERR("rom-size not allowed to be 0\n");
+        exit(1);
+    }
+
     ee->mem = g_malloc0(ee->rsize);
 
     if (ee->blk) {
-- 
2.11.0

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

* [PATCH v2 2/3] nvram: at24c: use a sane default for "rom-size"
  2018-03-19 21:30 ` [Qemu-devel] " Wolfram Sang
@ 2018-03-19 21:31   ` Wolfram Sang
  -1 siblings, 0 replies; 20+ messages in thread
From: Wolfram Sang @ 2018-03-19 21:31 UTC (permalink / raw)
  To: qemu-devel; +Cc: Philippe Mathieu-Daudé, linux-renesas-soc, Wolfram Sang

0 as "rom-size" will lead to an error message. Let's use the size of a
small 24c01 which has 128 byte.

Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
---
 hw/nvram/eeprom_at24c.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/hw/nvram/eeprom_at24c.c b/hw/nvram/eeprom_at24c.c
index ccf78b25e4..ab1ef686e2 100644
--- a/hw/nvram/eeprom_at24c.c
+++ b/hw/nvram/eeprom_at24c.c
@@ -28,6 +28,9 @@
 #define TYPE_AT24C_EE "at24c-eeprom"
 #define AT24C_EE(obj) OBJECT_CHECK(EEPROMState, (obj), TYPE_AT24C_EE)
 
+/* default is the size of a 24c01 EEPROM */
+#define AT24C_ROMSIZE_DEFAULT 128
+
 typedef struct EEPROMState {
     I2CSlave parent_obj;
 
@@ -171,7 +174,7 @@ void at24c_eeprom_reset(DeviceState *state)
 }
 
 static Property at24c_eeprom_props[] = {
-    DEFINE_PROP_UINT32("rom-size", EEPROMState, rsize, 0),
+    DEFINE_PROP_UINT32("rom-size", EEPROMState, rsize, AT24C_ROMSIZE_DEFAULT),
     DEFINE_PROP_BOOL("writable", EEPROMState, writable, true),
     DEFINE_PROP_DRIVE("drive", EEPROMState, blk),
     DEFINE_PROP_END_OF_LIST()
-- 
2.11.0

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

* [Qemu-devel] [PATCH v2 2/3] nvram: at24c: use a sane default for "rom-size"
@ 2018-03-19 21:31   ` Wolfram Sang
  0 siblings, 0 replies; 20+ messages in thread
From: Wolfram Sang @ 2018-03-19 21:31 UTC (permalink / raw)
  To: qemu-devel; +Cc: Philippe Mathieu-Daudé, linux-renesas-soc, Wolfram Sang

0 as "rom-size" will lead to an error message. Let's use the size of a
small 24c01 which has 128 byte.

Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
---
 hw/nvram/eeprom_at24c.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/hw/nvram/eeprom_at24c.c b/hw/nvram/eeprom_at24c.c
index ccf78b25e4..ab1ef686e2 100644
--- a/hw/nvram/eeprom_at24c.c
+++ b/hw/nvram/eeprom_at24c.c
@@ -28,6 +28,9 @@
 #define TYPE_AT24C_EE "at24c-eeprom"
 #define AT24C_EE(obj) OBJECT_CHECK(EEPROMState, (obj), TYPE_AT24C_EE)
 
+/* default is the size of a 24c01 EEPROM */
+#define AT24C_ROMSIZE_DEFAULT 128
+
 typedef struct EEPROMState {
     I2CSlave parent_obj;
 
@@ -171,7 +174,7 @@ void at24c_eeprom_reset(DeviceState *state)
 }
 
 static Property at24c_eeprom_props[] = {
-    DEFINE_PROP_UINT32("rom-size", EEPROMState, rsize, 0),
+    DEFINE_PROP_UINT32("rom-size", EEPROMState, rsize, AT24C_ROMSIZE_DEFAULT),
     DEFINE_PROP_BOOL("writable", EEPROMState, writable, true),
     DEFINE_PROP_DRIVE("drive", EEPROMState, blk),
     DEFINE_PROP_END_OF_LIST()
-- 
2.11.0

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

* [PATCH v2 3/3] nvram: at24c: use standard error reporting
  2018-03-19 21:30 ` [Qemu-devel] " Wolfram Sang
@ 2018-03-19 21:31   ` Wolfram Sang
  -1 siblings, 0 replies; 20+ messages in thread
From: Wolfram Sang @ 2018-03-19 21:31 UTC (permalink / raw)
  To: qemu-devel; +Cc: Philippe Mathieu-Daudé, linux-renesas-soc, Wolfram Sang

Replace the ERR macro with error_report() because fprintf is deprecated.
This also fixes the prefix printed out twice.

Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
---
 hw/nvram/eeprom_at24c.c | 17 ++++++-----------
 1 file changed, 6 insertions(+), 11 deletions(-)

diff --git a/hw/nvram/eeprom_at24c.c b/hw/nvram/eeprom_at24c.c
index ab1ef686e2..1560c9a46b 100644
--- a/hw/nvram/eeprom_at24c.c
+++ b/hw/nvram/eeprom_at24c.c
@@ -13,6 +13,7 @@
 #include "hw/hw.h"
 #include "hw/i2c/i2c.h"
 #include "sysemu/block-backend.h"
+#include "qemu/error-report.h"
 
 /* #define DEBUG_AT24C */
 
@@ -22,9 +23,6 @@
 #define DPRINTK(FMT, ...) do {} while (0)
 #endif
 
-#define ERR(FMT, ...) fprintf(stderr, TYPE_AT24C_EE " : " FMT, \
-                            ## __VA_ARGS__)
-
 #define TYPE_AT24C_EE "at24c-eeprom"
 #define AT24C_EE(obj) OBJECT_CHECK(EEPROMState, (obj), TYPE_AT24C_EE)
 
@@ -63,8 +61,7 @@ int at24c_eeprom_event(I2CSlave *s, enum i2c_event event)
         if (ee->blk && ee->changed) {
             int len = blk_pwrite(ee->blk, 0, ee->mem, ee->rsize, 0);
             if (len != ee->rsize) {
-                ERR(TYPE_AT24C_EE
-                        " : failed to write backing file\n");
+                error_report("failed to write backing file\n");
             }
             DPRINTK("Wrote to backing file\n");
         }
@@ -125,7 +122,7 @@ int at24c_eeprom_init(I2CSlave *i2c)
     EEPROMState *ee = AT24C_EE(i2c);
 
     if (!ee->rsize) {
-        ERR("rom-size not allowed to be 0\n");
+        error_report("rom-size not allowed to be 0\n");
         exit(1);
     }
 
@@ -135,7 +132,7 @@ int at24c_eeprom_init(I2CSlave *i2c)
         int64_t len = blk_getlength(ee->blk);
 
         if (len != ee->rsize) {
-            ERR(TYPE_AT24C_EE " : Backing file size %lu != %u\n",
+            error_report("Backing file size %lu != %u\n",
                     (unsigned long)len, (unsigned)ee->rsize);
             exit(1);
         }
@@ -143,8 +140,7 @@ int at24c_eeprom_init(I2CSlave *i2c)
         if (blk_set_perm(ee->blk, BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE,
                          BLK_PERM_ALL, &error_fatal) < 0)
         {
-            ERR(TYPE_AT24C_EE
-                    " : Backing file incorrect permission\n");
+            error_report("Backing file incorrect permission\n");
             exit(1);
         }
     }
@@ -166,8 +162,7 @@ void at24c_eeprom_reset(DeviceState *state)
         int len = blk_pread(ee->blk, 0, ee->mem, ee->rsize);
 
         if (len != ee->rsize) {
-            ERR(TYPE_AT24C_EE
-                    " : Failed initial sync with backing file\n");
+            error_report("Failed initial sync with backing file\n");
         }
         DPRINTK("Reset read backing file\n");
     }
-- 
2.11.0

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

* [Qemu-devel] [PATCH v2 3/3] nvram: at24c: use standard error reporting
@ 2018-03-19 21:31   ` Wolfram Sang
  0 siblings, 0 replies; 20+ messages in thread
From: Wolfram Sang @ 2018-03-19 21:31 UTC (permalink / raw)
  To: qemu-devel; +Cc: Philippe Mathieu-Daudé, linux-renesas-soc, Wolfram Sang

Replace the ERR macro with error_report() because fprintf is deprecated.
This also fixes the prefix printed out twice.

Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
---
 hw/nvram/eeprom_at24c.c | 17 ++++++-----------
 1 file changed, 6 insertions(+), 11 deletions(-)

diff --git a/hw/nvram/eeprom_at24c.c b/hw/nvram/eeprom_at24c.c
index ab1ef686e2..1560c9a46b 100644
--- a/hw/nvram/eeprom_at24c.c
+++ b/hw/nvram/eeprom_at24c.c
@@ -13,6 +13,7 @@
 #include "hw/hw.h"
 #include "hw/i2c/i2c.h"
 #include "sysemu/block-backend.h"
+#include "qemu/error-report.h"
 
 /* #define DEBUG_AT24C */
 
@@ -22,9 +23,6 @@
 #define DPRINTK(FMT, ...) do {} while (0)
 #endif
 
-#define ERR(FMT, ...) fprintf(stderr, TYPE_AT24C_EE " : " FMT, \
-                            ## __VA_ARGS__)
-
 #define TYPE_AT24C_EE "at24c-eeprom"
 #define AT24C_EE(obj) OBJECT_CHECK(EEPROMState, (obj), TYPE_AT24C_EE)
 
@@ -63,8 +61,7 @@ int at24c_eeprom_event(I2CSlave *s, enum i2c_event event)
         if (ee->blk && ee->changed) {
             int len = blk_pwrite(ee->blk, 0, ee->mem, ee->rsize, 0);
             if (len != ee->rsize) {
-                ERR(TYPE_AT24C_EE
-                        " : failed to write backing file\n");
+                error_report("failed to write backing file\n");
             }
             DPRINTK("Wrote to backing file\n");
         }
@@ -125,7 +122,7 @@ int at24c_eeprom_init(I2CSlave *i2c)
     EEPROMState *ee = AT24C_EE(i2c);
 
     if (!ee->rsize) {
-        ERR("rom-size not allowed to be 0\n");
+        error_report("rom-size not allowed to be 0\n");
         exit(1);
     }
 
@@ -135,7 +132,7 @@ int at24c_eeprom_init(I2CSlave *i2c)
         int64_t len = blk_getlength(ee->blk);
 
         if (len != ee->rsize) {
-            ERR(TYPE_AT24C_EE " : Backing file size %lu != %u\n",
+            error_report("Backing file size %lu != %u\n",
                     (unsigned long)len, (unsigned)ee->rsize);
             exit(1);
         }
@@ -143,8 +140,7 @@ int at24c_eeprom_init(I2CSlave *i2c)
         if (blk_set_perm(ee->blk, BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE,
                          BLK_PERM_ALL, &error_fatal) < 0)
         {
-            ERR(TYPE_AT24C_EE
-                    " : Backing file incorrect permission\n");
+            error_report("Backing file incorrect permission\n");
             exit(1);
         }
     }
@@ -166,8 +162,7 @@ void at24c_eeprom_reset(DeviceState *state)
         int len = blk_pread(ee->blk, 0, ee->mem, ee->rsize);
 
         if (len != ee->rsize) {
-            ERR(TYPE_AT24C_EE
-                    " : Failed initial sync with backing file\n");
+            error_report("Failed initial sync with backing file\n");
         }
         DPRINTK("Reset read backing file\n");
     }
-- 
2.11.0

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

* Re: [Qemu-devel] [PATCH v2 3/3] nvram: at24c: use standard error reporting
  2018-03-19 21:31   ` [Qemu-devel] " Wolfram Sang
  (?)
@ 2018-03-19 21:51   ` Eric Blake
  2018-03-19 22:07     ` Wolfram Sang
  -1 siblings, 1 reply; 20+ messages in thread
From: Eric Blake @ 2018-03-19 21:51 UTC (permalink / raw)
  To: Wolfram Sang, qemu-devel; +Cc: linux-renesas-soc, Philippe Mathieu-Daudé

On 03/19/2018 04:31 PM, Wolfram Sang wrote:
> Replace the ERR macro with error_report() because fprintf is deprecated.
> This also fixes the prefix printed out twice.
> 
> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
> ---
>   hw/nvram/eeprom_at24c.c | 17 ++++++-----------
>   1 file changed, 6 insertions(+), 11 deletions(-)
> 

> @@ -63,8 +61,7 @@ int at24c_eeprom_event(I2CSlave *s, enum i2c_event event)
>           if (ee->blk && ee->changed) {
>               int len = blk_pwrite(ee->blk, 0, ee->mem, ee->rsize, 0);
>               if (len != ee->rsize) {
> -                ERR(TYPE_AT24C_EE
> -                        " : failed to write backing file\n");
> +                error_report("failed to write backing file\n");

Drop the \n here and elsewhere in your patch; error_report() already 
does that for you.

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org

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

* Re: [Qemu-devel] [PATCH v2 0/3] nvram: at24c: fix problems related to "rom-size"
  2018-03-19 21:30 ` [Qemu-devel] " Wolfram Sang
@ 2018-03-19 21:52   ` no-reply
  -1 siblings, 0 replies; 20+ messages in thread
From: no-reply @ 2018-03-19 21:52 UTC (permalink / raw)
  To: wsa+renesas; +Cc: famz, qemu-devel, linux-renesas-soc, wsa+renesas, f4bug

Hi,

This series seems to have some coding style problems. See output below for
more information:

Type: series
Message-id: 20180319213101.6100-1-wsa+renesas@sang-engineering.com
Subject: [Qemu-devel] [PATCH v2 0/3] nvram: at24c: fix problems related to "rom-size"

=== TEST SCRIPT BEGIN ===
#!/bin/bash

BASE=base
n=1
total=$(git log --oneline $BASE.. | wc -l)
failed=0

git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram

commits="$(git log --format=%H --reverse $BASE..)"
for c in $commits; do
    echo "Checking PATCH $n/$total: $(git log -n 1 --format=%s $c)..."
    if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then
        failed=1
        echo
    fi
    n=$((n+1))
done

exit $failed
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
 * [new tag]               patchew/20180319213101.6100-1-wsa+renesas@sang-engineering.com -> patchew/20180319213101.6100-1-wsa+renesas@sang-engineering.com
Switched to a new branch 'test'
002d73a8fa nvram: at24c: use standard error reporting
6c4df3f9e8 nvram: at24c: use a sane default for "rom-size"
22640ea981 nvram: at24c: prevent segfault by checking "rom-size"

=== OUTPUT BEGIN ===
Checking PATCH 1/3: nvram: at24c: prevent segfault by checking "rom-size"...
Checking PATCH 2/3: nvram: at24c: use a sane default for "rom-size"...
Checking PATCH 3/3: nvram: at24c: use standard error reporting...
ERROR: Error messages should not contain newlines
#40: FILE: hw/nvram/eeprom_at24c.c:64:
+                error_report("failed to write backing file\n");

ERROR: Error messages should not contain newlines
#49: FILE: hw/nvram/eeprom_at24c.c:125:
+        error_report("rom-size not allowed to be 0\n");

ERROR: Error messages should not contain newlines
#58: FILE: hw/nvram/eeprom_at24c.c:135:
+            error_report("Backing file size %lu != %u\n",

ERROR: Error messages should not contain newlines
#68: FILE: hw/nvram/eeprom_at24c.c:143:
+            error_report("Backing file incorrect permission\n");

ERROR: Error messages should not contain newlines
#78: FILE: hw/nvram/eeprom_at24c.c:165:
+            error_report("Failed initial sync with backing file\n");

total: 5 errors, 0 warnings, 59 lines checked

Your patch has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

=== OUTPUT END ===

Test command exited with code: 1


---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to patchew-devel@freelists.org

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

* Re: [Qemu-devel] [PATCH v2 0/3] nvram: at24c: fix problems related to "rom-size"
@ 2018-03-19 21:52   ` no-reply
  0 siblings, 0 replies; 20+ messages in thread
From: no-reply @ 2018-03-19 21:52 UTC (permalink / raw)
  To: wsa+renesas; +Cc: famz, qemu-devel, linux-renesas-soc, f4bug

Hi,

This series seems to have some coding style problems. See output below for
more information:

Type: series
Message-id: 20180319213101.6100-1-wsa+renesas@sang-engineering.com
Subject: [Qemu-devel] [PATCH v2 0/3] nvram: at24c: fix problems related to "rom-size"

=== TEST SCRIPT BEGIN ===
#!/bin/bash

BASE=base
n=1
total=$(git log --oneline $BASE.. | wc -l)
failed=0

git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram

commits="$(git log --format=%H --reverse $BASE..)"
for c in $commits; do
    echo "Checking PATCH $n/$total: $(git log -n 1 --format=%s $c)..."
    if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then
        failed=1
        echo
    fi
    n=$((n+1))
done

exit $failed
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
 * [new tag]               patchew/20180319213101.6100-1-wsa+renesas@sang-engineering.com -> patchew/20180319213101.6100-1-wsa+renesas@sang-engineering.com
Switched to a new branch 'test'
002d73a8fa nvram: at24c: use standard error reporting
6c4df3f9e8 nvram: at24c: use a sane default for "rom-size"
22640ea981 nvram: at24c: prevent segfault by checking "rom-size"

=== OUTPUT BEGIN ===
Checking PATCH 1/3: nvram: at24c: prevent segfault by checking "rom-size"...
Checking PATCH 2/3: nvram: at24c: use a sane default for "rom-size"...
Checking PATCH 3/3: nvram: at24c: use standard error reporting...
ERROR: Error messages should not contain newlines
#40: FILE: hw/nvram/eeprom_at24c.c:64:
+                error_report("failed to write backing file\n");

ERROR: Error messages should not contain newlines
#49: FILE: hw/nvram/eeprom_at24c.c:125:
+        error_report("rom-size not allowed to be 0\n");

ERROR: Error messages should not contain newlines
#58: FILE: hw/nvram/eeprom_at24c.c:135:
+            error_report("Backing file size %lu != %u\n",

ERROR: Error messages should not contain newlines
#68: FILE: hw/nvram/eeprom_at24c.c:143:
+            error_report("Backing file incorrect permission\n");

ERROR: Error messages should not contain newlines
#78: FILE: hw/nvram/eeprom_at24c.c:165:
+            error_report("Failed initial sync with backing file\n");

total: 5 errors, 0 warnings, 59 lines checked

Your patch has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

=== OUTPUT END ===

Test command exited with code: 1


---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to patchew-devel@freelists.org

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

* Re: [Qemu-devel] [PATCH v2 3/3] nvram: at24c: use standard error reporting
  2018-03-19 21:51   ` Eric Blake
@ 2018-03-19 22:07     ` Wolfram Sang
  0 siblings, 0 replies; 20+ messages in thread
From: Wolfram Sang @ 2018-03-19 22:07 UTC (permalink / raw)
  To: Eric Blake
  Cc: Wolfram Sang, qemu-devel, linux-renesas-soc, Philippe Mathieu-Daudé

[-- Attachment #1: Type: text/plain, Size: 408 bytes --]


> > -                ERR(TYPE_AT24C_EE
> > -                        " : failed to write backing file\n");
> > +                error_report("failed to write backing file\n");
> 
> Drop the \n here and elsewhere in your patch; error_report() already does
> that for you.

Darn, I haven't installed my automatic-checkpatch-script for qemu yet :(
Sorry, will wait for more review comments and fix!


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH v2 2/3] nvram: at24c: use a sane default for "rom-size"
  2018-03-19 21:31   ` [Qemu-devel] " Wolfram Sang
@ 2018-03-20  0:45     ` Philippe Mathieu-Daudé
  -1 siblings, 0 replies; 20+ messages in thread
From: Philippe Mathieu-Daudé @ 2018-03-20  0:45 UTC (permalink / raw)
  To: Wolfram Sang, qemu-devel; +Cc: linux-renesas-soc

On 03/19/2018 10:31 PM, Wolfram Sang wrote:
> 0 as "rom-size" will lead to an error message. Let's use the size of a
> small 24c01 which has 128 byte.
> 
> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

> ---
>  hw/nvram/eeprom_at24c.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/nvram/eeprom_at24c.c b/hw/nvram/eeprom_at24c.c
> index ccf78b25e4..ab1ef686e2 100644
> --- a/hw/nvram/eeprom_at24c.c
> +++ b/hw/nvram/eeprom_at24c.c
> @@ -28,6 +28,9 @@
>  #define TYPE_AT24C_EE "at24c-eeprom"
>  #define AT24C_EE(obj) OBJECT_CHECK(EEPROMState, (obj), TYPE_AT24C_EE)
>  
> +/* default is the size of a 24c01 EEPROM */
> +#define AT24C_ROMSIZE_DEFAULT 128
> +
>  typedef struct EEPROMState {
>      I2CSlave parent_obj;
>  
> @@ -171,7 +174,7 @@ void at24c_eeprom_reset(DeviceState *state)
>  }
>  
>  static Property at24c_eeprom_props[] = {
> -    DEFINE_PROP_UINT32("rom-size", EEPROMState, rsize, 0),
> +    DEFINE_PROP_UINT32("rom-size", EEPROMState, rsize, AT24C_ROMSIZE_DEFAULT),
>      DEFINE_PROP_BOOL("writable", EEPROMState, writable, true),
>      DEFINE_PROP_DRIVE("drive", EEPROMState, blk),
>      DEFINE_PROP_END_OF_LIST()
> 

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

* Re: [Qemu-devel] [PATCH v2 2/3] nvram: at24c: use a sane default for "rom-size"
@ 2018-03-20  0:45     ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 20+ messages in thread
From: Philippe Mathieu-Daudé @ 2018-03-20  0:45 UTC (permalink / raw)
  To: Wolfram Sang, qemu-devel; +Cc: linux-renesas-soc

On 03/19/2018 10:31 PM, Wolfram Sang wrote:
> 0 as "rom-size" will lead to an error message. Let's use the size of a
> small 24c01 which has 128 byte.
> 
> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

> ---
>  hw/nvram/eeprom_at24c.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/nvram/eeprom_at24c.c b/hw/nvram/eeprom_at24c.c
> index ccf78b25e4..ab1ef686e2 100644
> --- a/hw/nvram/eeprom_at24c.c
> +++ b/hw/nvram/eeprom_at24c.c
> @@ -28,6 +28,9 @@
>  #define TYPE_AT24C_EE "at24c-eeprom"
>  #define AT24C_EE(obj) OBJECT_CHECK(EEPROMState, (obj), TYPE_AT24C_EE)
>  
> +/* default is the size of a 24c01 EEPROM */
> +#define AT24C_ROMSIZE_DEFAULT 128
> +
>  typedef struct EEPROMState {
>      I2CSlave parent_obj;
>  
> @@ -171,7 +174,7 @@ void at24c_eeprom_reset(DeviceState *state)
>  }
>  
>  static Property at24c_eeprom_props[] = {
> -    DEFINE_PROP_UINT32("rom-size", EEPROMState, rsize, 0),
> +    DEFINE_PROP_UINT32("rom-size", EEPROMState, rsize, AT24C_ROMSIZE_DEFAULT),
>      DEFINE_PROP_BOOL("writable", EEPROMState, writable, true),
>      DEFINE_PROP_DRIVE("drive", EEPROMState, blk),
>      DEFINE_PROP_END_OF_LIST()
> 

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

* Re: [PATCH v2 1/3] nvram: at24c: prevent segfault by checking "rom-size"
  2018-03-19 21:30   ` [Qemu-devel] " Wolfram Sang
@ 2018-03-20  0:48     ` Philippe Mathieu-Daudé
  -1 siblings, 0 replies; 20+ messages in thread
From: Philippe Mathieu-Daudé @ 2018-03-20  0:48 UTC (permalink / raw)
  To: Wolfram Sang, qemu-devel; +Cc: linux-renesas-soc

On 03/19/2018 10:30 PM, Wolfram Sang wrote:
> The value for "rom-size" is used as a divisor, so it must not be 0 or it
> will segfault. A size of 0 wouldn't make sense anyhow.
> 
> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
> ---
>  hw/nvram/eeprom_at24c.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/hw/nvram/eeprom_at24c.c b/hw/nvram/eeprom_at24c.c
> index 22183f5360..ccf78b25e4 100644
> --- a/hw/nvram/eeprom_at24c.c
> +++ b/hw/nvram/eeprom_at24c.c
> @@ -121,6 +121,11 @@ int at24c_eeprom_init(I2CSlave *i2c)
>  {
>      EEPROMState *ee = AT24C_EE(i2c);
>  
> +    if (!ee->rsize) {
> +        ERR("rom-size not allowed to be 0\n");

You can directly use error_report() in this patch.

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

> +        exit(1);
> +    }
> +
>      ee->mem = g_malloc0(ee->rsize);
>  
>      if (ee->blk) {
> 

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

* Re: [Qemu-devel] [PATCH v2 1/3] nvram: at24c: prevent segfault by checking "rom-size"
@ 2018-03-20  0:48     ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 20+ messages in thread
From: Philippe Mathieu-Daudé @ 2018-03-20  0:48 UTC (permalink / raw)
  To: Wolfram Sang, qemu-devel; +Cc: linux-renesas-soc

On 03/19/2018 10:30 PM, Wolfram Sang wrote:
> The value for "rom-size" is used as a divisor, so it must not be 0 or it
> will segfault. A size of 0 wouldn't make sense anyhow.
> 
> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
> ---
>  hw/nvram/eeprom_at24c.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/hw/nvram/eeprom_at24c.c b/hw/nvram/eeprom_at24c.c
> index 22183f5360..ccf78b25e4 100644
> --- a/hw/nvram/eeprom_at24c.c
> +++ b/hw/nvram/eeprom_at24c.c
> @@ -121,6 +121,11 @@ int at24c_eeprom_init(I2CSlave *i2c)
>  {
>      EEPROMState *ee = AT24C_EE(i2c);
>  
> +    if (!ee->rsize) {
> +        ERR("rom-size not allowed to be 0\n");

You can directly use error_report() in this patch.

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

> +        exit(1);
> +    }
> +
>      ee->mem = g_malloc0(ee->rsize);
>  
>      if (ee->blk) {
> 

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

* Re: [PATCH v2 3/3] nvram: at24c: use standard error reporting
  2018-03-19 21:31   ` [Qemu-devel] " Wolfram Sang
@ 2018-03-20  0:49     ` Philippe Mathieu-Daudé
  -1 siblings, 0 replies; 20+ messages in thread
From: Philippe Mathieu-Daudé @ 2018-03-20  0:49 UTC (permalink / raw)
  To: Wolfram Sang, qemu-devel; +Cc: linux-renesas-soc

On 03/19/2018 10:31 PM, Wolfram Sang wrote:
> Replace the ERR macro with error_report() because fprintf is deprecated.
> This also fixes the prefix printed out twice.
> 
> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
> ---
>  hw/nvram/eeprom_at24c.c | 17 ++++++-----------
>  1 file changed, 6 insertions(+), 11 deletions(-)
> 
> diff --git a/hw/nvram/eeprom_at24c.c b/hw/nvram/eeprom_at24c.c
> index ab1ef686e2..1560c9a46b 100644
> --- a/hw/nvram/eeprom_at24c.c
> +++ b/hw/nvram/eeprom_at24c.c
> @@ -13,6 +13,7 @@
>  #include "hw/hw.h"
>  #include "hw/i2c/i2c.h"
>  #include "sysemu/block-backend.h"
> +#include "qemu/error-report.h"
>  
>  /* #define DEBUG_AT24C */
>  
> @@ -22,9 +23,6 @@
>  #define DPRINTK(FMT, ...) do {} while (0)
>  #endif
>  
> -#define ERR(FMT, ...) fprintf(stderr, TYPE_AT24C_EE " : " FMT, \
> -                            ## __VA_ARGS__)
> -
>  #define TYPE_AT24C_EE "at24c-eeprom"
>  #define AT24C_EE(obj) OBJECT_CHECK(EEPROMState, (obj), TYPE_AT24C_EE)
>  
> @@ -63,8 +61,7 @@ int at24c_eeprom_event(I2CSlave *s, enum i2c_event event)
>          if (ee->blk && ee->changed) {
>              int len = blk_pwrite(ee->blk, 0, ee->mem, ee->rsize, 0);
>              if (len != ee->rsize) {
> -                ERR(TYPE_AT24C_EE
> -                        " : failed to write backing file\n");
> +                error_report("failed to write backing file\n");
>              }
>              DPRINTK("Wrote to backing file\n");
>          }
> @@ -125,7 +122,7 @@ int at24c_eeprom_init(I2CSlave *i2c)
>      EEPROMState *ee = AT24C_EE(i2c);
>  
>      if (!ee->rsize) {
> -        ERR("rom-size not allowed to be 0\n");
> +        error_report("rom-size not allowed to be 0\n");
>          exit(1);
>      }
>  
> @@ -135,7 +132,7 @@ int at24c_eeprom_init(I2CSlave *i2c)
>          int64_t len = blk_getlength(ee->blk);
>  
>          if (len != ee->rsize) {
> -            ERR(TYPE_AT24C_EE " : Backing file size %lu != %u\n",
> +            error_report("Backing file size %lu != %u\n",
>                      (unsigned long)len, (unsigned)ee->rsize);
>              exit(1);
>          }
> @@ -143,8 +140,7 @@ int at24c_eeprom_init(I2CSlave *i2c)
>          if (blk_set_perm(ee->blk, BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE,
>                           BLK_PERM_ALL, &error_fatal) < 0)
>          {
> -            ERR(TYPE_AT24C_EE
> -                    " : Backing file incorrect permission\n");
> +            error_report("Backing file incorrect permission\n");
>              exit(1);
>          }
>      }
> @@ -166,8 +162,7 @@ void at24c_eeprom_reset(DeviceState *state)
>          int len = blk_pread(ee->blk, 0, ee->mem, ee->rsize);
>  
>          if (len != ee->rsize) {
> -            ERR(TYPE_AT24C_EE
> -                    " : Failed initial sync with backing file\n");
> +            error_report("Failed initial sync with backing file\n");
>          }
>          DPRINTK("Reset read backing file\n");
>      }
> 

Without '\n':
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

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

* Re: [Qemu-devel] [PATCH v2 3/3] nvram: at24c: use standard error reporting
@ 2018-03-20  0:49     ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 20+ messages in thread
From: Philippe Mathieu-Daudé @ 2018-03-20  0:49 UTC (permalink / raw)
  To: Wolfram Sang, qemu-devel; +Cc: linux-renesas-soc

On 03/19/2018 10:31 PM, Wolfram Sang wrote:
> Replace the ERR macro with error_report() because fprintf is deprecated.
> This also fixes the prefix printed out twice.
> 
> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
> ---
>  hw/nvram/eeprom_at24c.c | 17 ++++++-----------
>  1 file changed, 6 insertions(+), 11 deletions(-)
> 
> diff --git a/hw/nvram/eeprom_at24c.c b/hw/nvram/eeprom_at24c.c
> index ab1ef686e2..1560c9a46b 100644
> --- a/hw/nvram/eeprom_at24c.c
> +++ b/hw/nvram/eeprom_at24c.c
> @@ -13,6 +13,7 @@
>  #include "hw/hw.h"
>  #include "hw/i2c/i2c.h"
>  #include "sysemu/block-backend.h"
> +#include "qemu/error-report.h"
>  
>  /* #define DEBUG_AT24C */
>  
> @@ -22,9 +23,6 @@
>  #define DPRINTK(FMT, ...) do {} while (0)
>  #endif
>  
> -#define ERR(FMT, ...) fprintf(stderr, TYPE_AT24C_EE " : " FMT, \
> -                            ## __VA_ARGS__)
> -
>  #define TYPE_AT24C_EE "at24c-eeprom"
>  #define AT24C_EE(obj) OBJECT_CHECK(EEPROMState, (obj), TYPE_AT24C_EE)
>  
> @@ -63,8 +61,7 @@ int at24c_eeprom_event(I2CSlave *s, enum i2c_event event)
>          if (ee->blk && ee->changed) {
>              int len = blk_pwrite(ee->blk, 0, ee->mem, ee->rsize, 0);
>              if (len != ee->rsize) {
> -                ERR(TYPE_AT24C_EE
> -                        " : failed to write backing file\n");
> +                error_report("failed to write backing file\n");
>              }
>              DPRINTK("Wrote to backing file\n");
>          }
> @@ -125,7 +122,7 @@ int at24c_eeprom_init(I2CSlave *i2c)
>      EEPROMState *ee = AT24C_EE(i2c);
>  
>      if (!ee->rsize) {
> -        ERR("rom-size not allowed to be 0\n");
> +        error_report("rom-size not allowed to be 0\n");
>          exit(1);
>      }
>  
> @@ -135,7 +132,7 @@ int at24c_eeprom_init(I2CSlave *i2c)
>          int64_t len = blk_getlength(ee->blk);
>  
>          if (len != ee->rsize) {
> -            ERR(TYPE_AT24C_EE " : Backing file size %lu != %u\n",
> +            error_report("Backing file size %lu != %u\n",
>                      (unsigned long)len, (unsigned)ee->rsize);
>              exit(1);
>          }
> @@ -143,8 +140,7 @@ int at24c_eeprom_init(I2CSlave *i2c)
>          if (blk_set_perm(ee->blk, BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE,
>                           BLK_PERM_ALL, &error_fatal) < 0)
>          {
> -            ERR(TYPE_AT24C_EE
> -                    " : Backing file incorrect permission\n");
> +            error_report("Backing file incorrect permission\n");
>              exit(1);
>          }
>      }
> @@ -166,8 +162,7 @@ void at24c_eeprom_reset(DeviceState *state)
>          int len = blk_pread(ee->blk, 0, ee->mem, ee->rsize);
>  
>          if (len != ee->rsize) {
> -            ERR(TYPE_AT24C_EE
> -                    " : Failed initial sync with backing file\n");
> +            error_report("Failed initial sync with backing file\n");
>          }
>          DPRINTK("Reset read backing file\n");
>      }
> 

Without '\n':
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

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

* Re: [PATCH v2 1/3] nvram: at24c: prevent segfault by checking "rom-size"
  2018-03-20  0:48     ` [Qemu-devel] " Philippe Mathieu-Daudé
@ 2018-03-20 11:07       ` Wolfram Sang
  -1 siblings, 0 replies; 20+ messages in thread
From: Wolfram Sang @ 2018-03-20 11:07 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé; +Cc: Wolfram Sang, qemu-devel, linux-renesas-soc

[-- Attachment #1: Type: text/plain, Size: 413 bytes --]


> > +    if (!ee->rsize) {
> > +        ERR("rom-size not allowed to be 0\n");
> 
> You can directly use error_report() in this patch.

My reasoning was that this patch is suitable for stable while the
error_report() stuff is not. I neither wanted to mix those two here nor
did I want to make the stable-patch depend on the non-stable patch. So,
I chose to use ERR here and fix all of ERR later. OK?


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [Qemu-devel] [PATCH v2 1/3] nvram: at24c: prevent segfault by checking "rom-size"
@ 2018-03-20 11:07       ` Wolfram Sang
  0 siblings, 0 replies; 20+ messages in thread
From: Wolfram Sang @ 2018-03-20 11:07 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé; +Cc: Wolfram Sang, qemu-devel, linux-renesas-soc

[-- Attachment #1: Type: text/plain, Size: 413 bytes --]


> > +    if (!ee->rsize) {
> > +        ERR("rom-size not allowed to be 0\n");
> 
> You can directly use error_report() in this patch.

My reasoning was that this patch is suitable for stable while the
error_report() stuff is not. I neither wanted to mix those two here nor
did I want to make the stable-patch depend on the non-stable patch. So,
I chose to use ERR here and fix all of ERR later. OK?


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

end of thread, other threads:[~2018-03-20 11:08 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-19 21:30 [PATCH v2 0/3] nvram: at24c: fix problems related to "rom-size" Wolfram Sang
2018-03-19 21:30 ` [Qemu-devel] " Wolfram Sang
2018-03-19 21:30 ` [PATCH v2 1/3] nvram: at24c: prevent segfault by checking "rom-size" Wolfram Sang
2018-03-19 21:30   ` [Qemu-devel] " Wolfram Sang
2018-03-20  0:48   ` Philippe Mathieu-Daudé
2018-03-20  0:48     ` [Qemu-devel] " Philippe Mathieu-Daudé
2018-03-20 11:07     ` Wolfram Sang
2018-03-20 11:07       ` [Qemu-devel] " Wolfram Sang
2018-03-19 21:31 ` [PATCH v2 2/3] nvram: at24c: use a sane default for "rom-size" Wolfram Sang
2018-03-19 21:31   ` [Qemu-devel] " Wolfram Sang
2018-03-20  0:45   ` Philippe Mathieu-Daudé
2018-03-20  0:45     ` [Qemu-devel] " Philippe Mathieu-Daudé
2018-03-19 21:31 ` [PATCH v2 3/3] nvram: at24c: use standard error reporting Wolfram Sang
2018-03-19 21:31   ` [Qemu-devel] " Wolfram Sang
2018-03-19 21:51   ` Eric Blake
2018-03-19 22:07     ` Wolfram Sang
2018-03-20  0:49   ` Philippe Mathieu-Daudé
2018-03-20  0:49     ` [Qemu-devel] " Philippe Mathieu-Daudé
2018-03-19 21:52 ` [Qemu-devel] [PATCH v2 0/3] nvram: at24c: fix problems related to "rom-size" no-reply
2018-03-19 21:52   ` no-reply

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.