[PATCH v3 2/3] arm: at91: simplify soc setup

2018-01-15 Thread Sam Ravnborg
The at91 soc support inherited a complex scheme
from the kernel.
This schme did not really give any benefits, and when
starting to migrate at91sam9263ek to use DT it started
to get in the way for a proper way to do things.

Replace the former setup with a simple function
pointer that can be called from setup.c.

Signed-off-by: Sam Ravnborg 
Reviewed-by: Andrey Smirnov 
---
 arch/arm/mach-at91/at91rm9200.c  | 10 +++---
 arch/arm/mach-at91/at91sam9260.c | 10 +++---
 arch/arm/mach-at91/at91sam9261.c | 10 +++---
 arch/arm/mach-at91/at91sam9263.c | 10 +++---
 arch/arm/mach-at91/at91sam9g45.c | 10 +++---
 arch/arm/mach-at91/at91sam9n12.c | 10 +++---
 arch/arm/mach-at91/generic.h |  9 -
 arch/arm/mach-at91/sama5d3.c | 10 +++---
 arch/arm/mach-at91/sama5d4.c | 10 +++---
 arch/arm/mach-at91/setup.c   | 26 +++---
 arch/arm/mach-at91/soc.h | 76 
 11 files changed, 60 insertions(+), 131 deletions(-)
 delete mode 100644 arch/arm/mach-at91/soc.h

diff --git a/arch/arm/mach-at91/at91rm9200.c b/arch/arm/mach-at91/at91rm9200.c
index d12e8d97b..ba680eb81 100644
--- a/arch/arm/mach-at91/at91rm9200.c
+++ b/arch/arm/mach-at91/at91rm9200.c
@@ -4,7 +4,6 @@
 #include 
 #include 
 
-#include "soc.h"
 #include "clock.h"
 #include "generic.h"
 
@@ -235,6 +234,9 @@ static void __init at91rm9200_initialize(void)
at91_add_rm9200_gpio(3, AT91RM9200_BASE_PIOD);
 }
 
-AT91_SOC_START(rm9200)
-   .init = at91rm9200_initialize,
-AT91_SOC_END
+static int at91rm9200_setup(void)
+{
+   at91_boot_soc = at91rm9200_initialize;
+   return 0;
+}
+pure_initcall(at91rm9200_setup);
diff --git a/arch/arm/mach-at91/at91sam9260.c b/arch/arm/mach-at91/at91sam9260.c
index fbd788414..8975bf466 100644
--- a/arch/arm/mach-at91/at91sam9260.c
+++ b/arch/arm/mach-at91/at91sam9260.c
@@ -4,7 +4,6 @@
 #include 
 #include 
 
-#include "soc.h"
 #include "generic.h"
 #include "clock.h"
 
@@ -236,6 +235,9 @@ static void at91sam9260_initialize(void)
at91_add_sam9_smc(DEVICE_ID_SINGLE, AT91SAM9260_BASE_SMC, 0x200);
 }
 
-AT91_SOC_START(sam9260)
-   .init = at91sam9260_initialize,
-AT91_SOC_END
+static int at91sam9260_setup(void)
+{
+   at91_boot_soc = at91sam9260_initialize;
+   return 0;
+}
+pure_initcall(at91sam9260_setup);
diff --git a/arch/arm/mach-at91/at91sam9261.c b/arch/arm/mach-at91/at91sam9261.c
index 37a65ecd3..35aaa9c96 100644
--- a/arch/arm/mach-at91/at91sam9261.c
+++ b/arch/arm/mach-at91/at91sam9261.c
@@ -4,7 +4,6 @@
 #include 
 #include 
 
-#include "soc.h"
 #include "generic.h"
 #include "clock.h"
 
@@ -228,6 +227,9 @@ static void at91sam9261_initialize(void)
at91_add_sam9_smc(DEVICE_ID_SINGLE, AT91SAM9261_BASE_SMC, 0x200);
 }
 
-AT91_SOC_START(sam9261)
-   .init = at91sam9261_initialize,
-AT91_SOC_END
+static int at91sam9261_setup(void)
+{
+   at91_boot_soc = at91sam9261_initialize;
+   return 0;
+}
+pure_initcall(at91sam9261_setup);
diff --git a/arch/arm/mach-at91/at91sam9263.c b/arch/arm/mach-at91/at91sam9263.c
index 35d187b4b..ee48115ea 100644
--- a/arch/arm/mach-at91/at91sam9263.c
+++ b/arch/arm/mach-at91/at91sam9263.c
@@ -4,7 +4,6 @@
 #include 
 #include 
 
-#include "soc.h"
 #include "clock.h"
 #include "generic.h"
 
@@ -249,6 +248,9 @@ static void at91sam9263_initialize(void)
at91_add_sam9_smc(1, AT91SAM9263_BASE_SMC1, 0x200);
 }
 
-AT91_SOC_START(sam9263)
-   .init = at91sam9263_initialize,
-AT91_SOC_END
+static int at91sam9263_setup(void)
+{
+   at91_boot_soc = at91sam9263_initialize;
+   return 0;
+}
+pure_initcall(at91sam9263_setup);
diff --git a/arch/arm/mach-at91/at91sam9g45.c b/arch/arm/mach-at91/at91sam9g45.c
index ce6ce90db..c70036b38 100644
--- a/arch/arm/mach-at91/at91sam9g45.c
+++ b/arch/arm/mach-at91/at91sam9g45.c
@@ -6,7 +6,6 @@
 #include 
 #include 
 
-#include "soc.h"
 #include "generic.h"
 #include "clock.h"
 
@@ -264,6 +263,9 @@ static void at91sam9g45_initialize(void)
at91_add_sam9_smc(DEVICE_ID_SINGLE, AT91SAM9G45_BASE_SMC, 0x200);
 }
 
-AT91_SOC_START(sam9g45)
-   .init = at91sam9g45_initialize,
-AT91_SOC_END
+static int at91sam9g45_setup(void)
+{
+   at91_boot_soc = at91sam9g45_initialize;
+   return 0;
+}
+pure_initcall(at91sam9g45_setup);
diff --git a/arch/arm/mach-at91/at91sam9n12.c b/arch/arm/mach-at91/at91sam9n12.c
index c551f9a74..7ab44e496 100644
--- a/arch/arm/mach-at91/at91sam9n12.c
+++ b/arch/arm/mach-at91/at91sam9n12.c
@@ -6,7 +6,6 @@
 #include 
 #include 
 
-#include "soc.h"
 #include "generic.h"
 #include "clock.h"
 
@@ -220,6 +219,9 @@ static void at91sam9n12_initialize(void)
at91_add_sam9_smc(DEVICE_ID_SINGLE, AT91SAM9N12_BASE_SMC, 0x200);
 }
 
-AT91_SOC_START(sam9n12)
-   .init = at91sam9n12_initialize,
-AT91_SOC_END
+static int at91sam9n12_setup(void)
+{
+   at91_boot_soc = at91sam9n12_initialize;
+   return 0;
+}
+pure_initcall(at91sam9n12_setup);
diff --git 

[PATCH v3 3/3] at91sam9263ek: enable DT support

2018-01-15 Thread Sam Ravnborg
Add at91sam9263ek.dts to build.
Include mmc1 in at91sam9263ek.dts, as mmc1 is what the evaluation
kit uses for the SD card.

Add DT specific of_init
Adjust build to drop non-DT files from mach-at91

RomBOOT
>AT91Bootstrap 3.0.1
patch-0.8 64MB Ram
Load from SD-Card
Loading from SD-Card
Open: u-boot.bin
Loading from SD-Card - Success

barebox 2017.12.0-00036-gda46de29e #23 Sun Dec 31 09:15:39 CET 2017

Board: Atmel at91sam9263ek
gpio-at91 f200.gpio: AT91 gpio driver registered
gpio-at91 f400.gpio: AT91 gpio driver registered
gpio-at91 f600.gpio: AT91 gpio driver registered
gpio-at91 f800.gpio: AT91 gpio driver registered
gpio-at91 fa00.gpio: AT91 gpio driver registered
pinctrl-at91 pinctrl.2: AT91 pinctrl registered
AT91: Detected soc type: at91sam9263
AT91: Detected soc subtype: Unknown
mdio_bus: miibus0: probed
macb fffbc000.ethernet: Cadence MACB at 0xfffbc000
at91_udc fff78000.gadget: at91_udc version 3 May 2006
atmel_mci fff8.mmc: version: 0x210
atmel_mci fff8.mmc: registered as fff8.mmc
atmel_mci fff84000.mmc: version: 0x210
atmel_mci fff84000.mmc: registered as fff84000.mmc
malloc space: 0x239fab00 -> 0x23dfaaff (size 4 MiB)
barebox-environment environment.6: probe failed: No such device
environment load /dev/env0: No such file or directory
Maybe you have to create the partition.
running /env/bin/init...
\e[?25h
Hit any key to stop autoboot:3
barebox@Atmel at91sam9263ek:/ iomem
0x - 0x (size 0x) iomem
  0x0030 - 0x00313fff (size 0x00014000) 30.sram
  0x0050 - 0x00503fff (size 0x4000) 50.sram
  0x0070 - 0x00700fff (size 0x1000) 70.fb
  0x2000 - 0x23ff (size 0x0400) ram0
0x239fab00 - 0x23dfaaff (size 0x0040) malloc space
0x23dfab00 - 0x23dfffe2 (size 0x54e3) board data
0x23e0 - 0x23e53cc8 (size 0x00053cc9) barebox
0x23e53cc9 - 0x23e6404f (size 0x00010387) barebox data
0x23e64050 - 0x23e6754b (size 0x34fc) bss
0x23fe4000 - 0x23fe7fff (size 0x4000) ttb
0x23fe8000 - 0x23fe (size 0x8000) stack
  0xfff78000 - 0xfff7bfff (size 0x4000) fff78000.gadget
  0xfff8 - 0xfff805ff (size 0x0600) fff8.mmc
  0xfff84000 - 0xfff845ff (size 0x0600) fff84000.mmc
  0xfff8c000 - 0xfff8c1ff (size 0x0200) fff8c000.serial
  0xfffbc000 - 0xfffbc0ff (size 0x0100) fffbc000.ethernet
  0xee00 - 0xefff (size 0x0200) ee00.serial
  0xf200 - 0xf3ff (size 0x0200) f200.gpio
  0xf400 - 0xf5ff (size 0x0200) f400.gpio
  0xf600 - 0xf7ff (size 0x0200) f600.gpio
  0xf800 - 0xf9ff (size 0x0200) f800.gpio
  0xfa00 - 0xfbff (size 0x0200) fa00.gpio
  0xfd30 - 0xfd3e (size 0x000f) fd30.timer
barebox@Atmel at91sam9263ek:/ devinfo
`-- global
`-- nv
`-- platform
   `-- mem0
  `-- 0x-0x03ff (64 MiB): /dev/ram0
   `-- 30.sram
  `-- 0x-0x00013fff (80 KiB): /dev/sram0
   `-- 50.sram
  `-- 0x-0x3fff (16 KiB): /dev/sram1
   `-- ahb.0
  `-- apb.1
 `-- f000.interrupt-controller
 `-- fc00.pmc
 `-- e200.ramc
 `-- e400.smc
 `-- e800.ramc
 `-- ea00.smc
 `-- ec00.matrix
 `-- fd30.timer
 `-- fff7c000.timer
 `-- fd00.rstc
 `-- fd10.shdwc
 `-- pinctrl.2
`-- f200.gpio
`-- f400.gpio
`-- f600.gpio
`-- f800.gpio
`-- fa00.gpio
 `-- ee00.serial
`-- cs0
   `-- 0x-0x (   0 Bytes): /dev/cs0
 `-- fff8c000.serial
`-- cs1
   `-- 0x-0x (   0 Bytes): /dev/cs1
 `-- fffbc000.ethernet
`-- miibus0
`-- eth0
 `-- fff78000.gadget
`-- usbgadget
 `-- fff8.mmc
`-- mci0
 `-- fff84000.mmc
`-- mci1
 `-- fd40.watchdog
 `-- fffa4000.spi
 `-- fffac000.can
  `-- 70.fb
  `-- a0.ohci
  `-- 1000.ebi
   `-- i2c-gpio-0.3
   `-- leds.4
   `-- gpio_keys.5
   `-- cs2
  `-- 0x-0x (   0 Bytes): /dev/cs2
   `-- soc
   `-- mem1
  `-- 0x-0xfffe ( 4 GiB): /dev/mem
   `-- environment.6
`-- mdio_bus
`-- fs
   `-- ramfs0
   `-- devfs0
`-- net
`-- udc0
`-- fb0
   `-- 0x-0x000257ff (   150 KiB): /dev/fb0
barebox@Atmel at91sam9263ek:/ drvinfo
Driver  Device(s)

syscon
at91-pit
fd30.timer
gpio-at91
f200.gpio
f400.gpio
f600.gpio
f800.gpio
fa00.gpio
pinctrl-at91
pinctrl.2
atmel_usart
ee00.serial
fff8c000.serial
ramfs
ramfs0
devfs
devfs0
fat
tftp
at91sam9-smc
Generic PHY
macb
fffbc000.ethernet

[PATCH v3 0/3] Enable DT support for AT91SAM9263EK

2018-01-15 Thread Sam Ravnborg
This is version 3 of a patchset to enable
device tree support for AT91SAM9263EK.

The patchset is made on top of previous
patches posted that move reset code to
the board files for at91 boards.
(Which are already part of -next)

On the quest towards getting so far several drivers was
converted to support DT.
These patches went in around august.

There was also issues with mach-at91 calling code
in the board directory (dependency in the
wrong direction).
This was fixed in "at91: move reset .." which is
pending (already posted).

I have failed to get the bootstrap mode to work.
It stops somewhere - and I have not invested enough
time to figure out where and why things goes wrong.
bootstrap mode was also broken before these patches.
No JTAG debugger available to help me.
And then I have at91bootstrap that works so motivation
was not too high.

I do not think the NAND support works either.
The device tree introduces some nand-controller
stuff that is not supported by barebox (at least I assume so).
And this part I did not look further into.

Next step is to get a proprietary board up and
running (which uses NOR flash).
But I wanted this patchset out in the open first.

Thanks for feedback so far - especially from Andrey.

Sam

v2 => v3
- Squashed commit introducing support for multi image
  with the commit to add DT support
- Fixed init of smc


v1 => v2
Based on feedback from Andrey (thanks!)
Patches reworked and combined as a result of this

- Included two patches that makes some general
  improvements to mach-at91.
  (Updated since the RFC versions sent yesterday)

  - Move irq_fixup, thus allowing us to call this
from board code. This makes it possible to have
less dependencies between board code and the processor
specific files in mach-at91.

  - Simplified soc setup. With this change setup.c
no longer requires that at least one of the
processor specific files are built.

- Create a minimal dts file, based on top of the
  dts file supplied from the kernel.

- Utilise gpio-hog - to setup gpio for PHY.

- Simpler Makefile logic in board Makefile
  It is now obvious that init.c is only used for
  bootstrap

- Processor specific files in mach-at91 no longer
  used when DT is enabled

- Use IS_ENABLED() when it makes code simpler


Sam Ravnborg (3):
  arm: at91: move irq_fixup to header file
  arm: at91: simplify soc setup
  at91sam9263ek: enable DT support

 arch/arm/boards/at91sam9263ek/Makefile|  4 +-
 arch/arm/boards/at91sam9263ek/lowlevel_init.c | 17 +++--
 arch/arm/boards/at91sam9263ek/of_init.c   | 93 +++
 arch/arm/configs/at91sam9263ek_defconfig  | 10 ++-
 arch/arm/dts/Makefile |  2 +-
 arch/arm/dts/at91sam9263ek.dts| 48 ++
 arch/arm/mach-at91/Kconfig| 30 ++---
 arch/arm/mach-at91/Makefile   |  6 +-
 arch/arm/mach-at91/at91rm9200.c   | 10 +--
 arch/arm/mach-at91/at91sam9260.c  | 10 +--
 arch/arm/mach-at91/at91sam9260_devices.c  |  1 +
 arch/arm/mach-at91/at91sam9261.c  | 10 +--
 arch/arm/mach-at91/at91sam9261_devices.c  |  1 +
 arch/arm/mach-at91/at91sam9263.c  | 10 +--
 arch/arm/mach-at91/at91sam9263_devices.c  |  1 +
 arch/arm/mach-at91/at91sam9g45.c  | 10 +--
 arch/arm/mach-at91/at91sam9g45_devices.c  |  1 +
 arch/arm/mach-at91/at91sam9n12.c  | 10 +--
 arch/arm/mach-at91/generic.h  | 11 +++-
 arch/arm/mach-at91/include/mach/at91_rtt.h| 16 +
 arch/arm/mach-at91/irq_fixup.c| 22 ---
 arch/arm/mach-at91/sama5d3.c  | 10 +--
 arch/arm/mach-at91/sama5d4.c  | 10 +--
 arch/arm/mach-at91/setup.c| 26 ++--
 arch/arm/mach-at91/soc.h  | 76 --
 images/Makefile.at91  |  4 ++
 26 files changed, 277 insertions(+), 172 deletions(-)


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH 1/2] common: state: Add property to protect existing data

2018-01-15 Thread Daniel Schultz

Hi,

just wanted to remind you to these patches.

Daniel


On 12/14/2017 04:51 PM, Daniel Schultz wrote:

After an update to a newer barebox version with an enabled state
framework, existing data in storage memories could be overwritten.

Add a new property to check in front of every write task, if the meta
magic field only contains the magic number, zeros or ones.

Signed-off-by: Daniel Schultz 
---
  .../devicetree/bindings/barebox/barebox,state.rst |  3 +++
  common/state/backend_bucket_direct.c  |  2 ++
  common/state/backend_storage.c|  1 +
  common/state/state.c  | 19 ++-
  common/state/state.h  |  2 ++
  5 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/barebox/barebox,state.rst 
b/Documentation/devicetree/bindings/barebox/barebox,state.rst
index cebb5f8..db5b041 100644
--- a/Documentation/devicetree/bindings/barebox/barebox,state.rst
+++ b/Documentation/devicetree/bindings/barebox/barebox,state.rst
@@ -55,6 +55,9 @@ Optional Properties
  * ``algo``: A HMAC algorithm used to detect manipulation of the data
or header, sensible values follow this pattern ``hmac()``,
e.g. ``hmac(sha256)``. Only available for the ``backend-type`` ``raw``.
+* ``keep-previous-content``: Check if a the bucket meta magic field contains
+  other data than the magic value. If so, the backend will not write the state
+  to prevent unconditionally overwrites of existing data.
  
  .. note:: For the ``backend-storage-type`` the keyword ``noncircular`` is still

 supported as a fall back to an old storage format. Recommendation is to not
diff --git a/common/state/backend_bucket_direct.c 
b/common/state/backend_bucket_direct.c
index 958696e..9d6a337 100644
--- a/common/state/backend_bucket_direct.c
+++ b/common/state/backend_bucket_direct.c
@@ -69,6 +69,8 @@ static int state_backend_bucket_direct_read(struct 
state_backend_storage_bucket
if (meta.magic == direct_magic) {
read_len = meta.written_length;
} else {
+   if (meta.magic != ~0 && !!meta.magic)
+   bucket->wrong_magic = 1;
if (!IS_ENABLED(CONFIG_STATE_BACKWARD_COMPATIBLE)) {
dev_err(direct->dev, "No meta data header found\n");
dev_dbg(direct->dev, "Enable backward compatibility or 
increase stride size\n");
diff --git a/common/state/backend_storage.c b/common/state/backend_storage.c
index c6ebe86..f0a169d 100644
--- a/common/state/backend_storage.c
+++ b/common/state/backend_storage.c
@@ -152,6 +152,7 @@ int state_storage_read(struct state_backend_storage 
*storage,
 * one we want to use.
 */
list_for_each_entry(bucket, >buckets, bucket_list) {
+   bucket->wrong_magic = 0;
ret = bucket->read(bucket, >buf, >len);
if (ret == -EUCLEAN)
bucket->needs_refresh = 1;
diff --git a/common/state/state.c b/common/state/state.c
index 6399bd3..e110542 100644
--- a/common/state/state.c
+++ b/common/state/state.c
@@ -44,6 +44,9 @@ int state_save(struct state *state)
void *buf;
ssize_t len;
int ret;
+   struct state_backend_storage_bucket *bucket;
+   struct state_backend_storage *storage;
+   bool has_content;
  
  	if (!state->dirty)

return 0;
@@ -55,7 +58,18 @@ int state_save(struct state *state)
return ret;
}
  
-	ret = state_storage_write(>storage, buf, len);

+   storage = >storage;
+   if (state->keep_prev_content) {
+   has_content = 0;
+   list_for_each_entry(bucket, >buckets, bucket_list)
+   has_content |= bucket->wrong_magic;
+   if (has_content) {
+   dev_dbg(>dev, "Found content on a backend.\n");
+   goto out;
+   }
+   }
+
+   ret = state_storage_write(storage, buf, len);
if (ret) {
dev_err(>dev, "Failed to write packed state, %d\n", ret);
goto out;
@@ -605,6 +619,9 @@ struct state *state_new_from_node(struct device_node *node, 
char *path,
}
}
  
+	state->keep_prev_content = of_property_read_bool(node,

+   
"keep-previous-content");
+
state->backend_path = xstrdup(path);
  
  	ret = of_property_read_string(node, "backend-type", _type);

diff --git a/common/state/state.h b/common/state/state.h
index fcc6b9f..a411b96 100644
--- a/common/state/state.h
+++ b/common/state/state.h
@@ -46,6 +46,7 @@ struct state_backend_storage_bucket {
void *buf;
ssize_t len;
bool needs_refresh;
+   bool wrong_magic;
  };
  
  /**

@@ -105,6 +106,7 @@ struct state {
char *of_path;
const char *name;
uint32_t 

[PATCH v2 2/3] lib: parse_area_spec: part of the area spec after -/+ should start with a digit

2018-01-15 Thread Peter Mamonov
Signed-off-by: Peter Mamonov 
---
 lib/misc.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/lib/misc.c b/lib/misc.c
index 1767043d1..fc2c45aa4 100644
--- a/lib/misc.c
+++ b/lib/misc.c
@@ -96,6 +96,9 @@ int parse_area_spec(const char *str, loff_t *start, loff_t 
*size)
 
if (*str == '-') {
/* beginning and end given */
+   if (!isdigit(*(str + 1)))
+   return -1;
+
end = strtoull_suffix(str + 1, NULL, 0);
if (end < *start) {
printf("end < start\n");
@@ -107,6 +110,9 @@ int parse_area_spec(const char *str, loff_t *start, loff_t 
*size)
 
if (*str == '+') {
/* beginning and size given */
+   if (!isdigit(*(str + 1)))
+   return -1;
+
*size = strtoull_suffix(str + 1, NULL, 0);
goto success;
}
-- 
2.11.0


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH v2 3/3] lib: parse_area_spec: no extra symbols after area spec are allowed except for spaces

2018-01-15 Thread Peter Mamonov
Signed-off-by: Peter Mamonov 
---
 lib/misc.c | 15 ++-
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/lib/misc.c b/lib/misc.c
index fc2c45aa4..4b62f8771 100644
--- a/lib/misc.c
+++ b/lib/misc.c
@@ -79,7 +79,7 @@ EXPORT_SYMBOL(strtoul_suffix);
 int parse_area_spec(const char *str, loff_t *start, loff_t *size)
 {
char *endp;
-   loff_t end, _start;
+   loff_t end, _start, _size;
 
if (!isdigit(*str))
return -1;
@@ -90,7 +90,7 @@ int parse_area_spec(const char *str, loff_t *start, loff_t 
*size)
 
if (!*str) {
/* beginning given, but no size, assume maximum size */
-   *size = ~0;
+   _size = ~0;
goto success;
}
 
@@ -99,12 +99,13 @@ int parse_area_spec(const char *str, loff_t *start, loff_t 
*size)
if (!isdigit(*(str + 1)))
return -1;
 
-   end = strtoull_suffix(str + 1, NULL, 0);
+   end = strtoull_suffix(str + 1, , 0);
+   str = endp;
if (end < *start) {
printf("end < start\n");
return -1;
}
-   *size = end - *start + 1;
+   _size = end - *start + 1;
goto success;
}
 
@@ -113,14 +114,18 @@ int parse_area_spec(const char *str, loff_t *start, 
loff_t *size)
if (!isdigit(*(str + 1)))
return -1;
 
-   *size = strtoull_suffix(str + 1, NULL, 0);
+   _size = strtoull_suffix(str + 1, , 0);
+   str = endp;
goto success;
}
 
return -1;
 
 success:
+   if (*str && !isspace(*str))
+   return -1;
*start = _start;
+   *size = _size;
return 0;
 }
 EXPORT_SYMBOL(parse_area_spec);
-- 
2.11.0


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH v2 1/3] lib: parse_area_spec: don't modify *start value if parse failed

2018-01-15 Thread Peter Mamonov
Signed-off-by: Peter Mamonov 
---
 lib/misc.c | 14 +-
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/lib/misc.c b/lib/misc.c
index 62ddd6677..1767043d1 100644
--- a/lib/misc.c
+++ b/lib/misc.c
@@ -79,19 +79,19 @@ EXPORT_SYMBOL(strtoul_suffix);
 int parse_area_spec(const char *str, loff_t *start, loff_t *size)
 {
char *endp;
-   loff_t end;
+   loff_t end, _start;
 
if (!isdigit(*str))
return -1;
 
-   *start = strtoull_suffix(str, , 0);
+   _start = strtoull_suffix(str, , 0);
 
str = endp;
 
if (!*str) {
/* beginning given, but no size, assume maximum size */
*size = ~0;
-   return 0;
+   goto success;
}
 
if (*str == '-') {
@@ -102,15 +102,19 @@ int parse_area_spec(const char *str, loff_t *start, 
loff_t *size)
return -1;
}
*size = end - *start + 1;
-   return 0;
+   goto success;
}
 
if (*str == '+') {
/* beginning and size given */
*size = strtoull_suffix(str + 1, NULL, 0);
-   return 0;
+   goto success;
}
 
return -1;
+
+success:
+   *start = _start;
+   return 0;
 }
 EXPORT_SYMBOL(parse_area_spec);
-- 
2.11.0


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox