Skip to contentSkip to conversation

state: backend_bucket_circular: fix for non power of 2 writesize

PATCH Applied Ladislav Michl 2 participants 2 messages Sep 25, 2018 – Sep 26, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 state: backend_bucket_circular: fix for non power of 2 writesize

backend_bucket_circular currently assumes writesize is power of 2, which makes it fail on dataflash devices, where this assumption is false.

---
 common/state/backend_bucket_circular.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
common/state/backend_bucket_circular.c +2 -2
index 933493e22..0529421a2 100644
@@ -248,7 +248,7 @@ static int state_backend_bucket_circular_read(struct state_backend_storage_bucke
 		circ->write_area = 0;
 		dev_info(circ->dev, "Detected old on-storage format\n");
 	} else if (circ->last_written_length > circ->write_area
-		   || !IS_ALIGNED(circ->last_written_length, circ->writesize)) {
+		   || (circ->last_written_length % circ->writesize != 0)) {
 		circ->write_area = 0;
 		dev_err(circ->dev, "Error, invalid number of bytes written last time %d\n",
 			circ->last_written_length);
@@ -295,7 +295,7 @@ static int state_backend_bucket_circular_write(struct state_backend_storage_buck
 	    get_bucket_circular(bucket);
 	off_t offset;
 	struct state_backend_storage_bucket_circular_meta *meta;
-	uint32_t written_length = ALIGN(len + sizeof(*meta), circ->writesize);
+	uint32_t written_length = roundup(len + sizeof(*meta), circ->writesize);
 	int ret;
 	void *write_buf;
 
Signature · 7 lines
2.19.0


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Applied
#1 lore raw
Quoted 8 lines · Ladislav Michl

backend_bucket_circular currently assumes writesize is power of 2, which makes it fail on dataflash devices, where this assumption is false.

---
 common/state/backend_bucket_circular.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Applied, thanks

Sascha

Quoted 32 lines
common/state/backend_bucket_circular.c +2 -2
index 933493e22..0529421a2 100644
@@ -248,7 +248,7 @@ static int state_backend_bucket_circular_read(struct state_backend_storage_bucke
 		circ->write_area = 0;
 		dev_info(circ->dev, "Detected old on-storage format\n");
 	} else if (circ->last_written_length > circ->write_area
-		   || !IS_ALIGNED(circ->last_written_length, circ->writesize)) {
+		   || (circ->last_written_length % circ->writesize != 0)) {
 		circ->write_area = 0;
 		dev_err(circ->dev, "Error, invalid number of bytes written last time %d\n",
 			circ->last_written_length);
@@ -295,7 +295,7 @@ static int state_backend_bucket_circular_write(struct state_backend_storage_buck
 	    get_bucket_circular(bucket);
 	off_t offset;
 	struct state_backend_storage_bucket_circular_meta *meta;
-	uint32_t written_length = ALIGN(len + sizeof(*meta), circ->writesize);
+	uint32_t written_length = roundup(len + sizeof(*meta), circ->writesize);
 	int ret;
 	void *write_buf;
 
Signature · 7 lines
2.19.0


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox