All of lore.kernel.org
 help / color / mirror / Atom feed
From: Frieder Schrempf <frieder@fris.de>
To: Lukasz Majewski <lukma@denx.de>, u-boot@lists.denx.de
Cc: Heiko Thiery <heiko.thiery@gmail.com>,
	Michael Walle <michael@walle.cc>,
	Frieder Schrempf <frieder.schrempf@kontron.de>,
	Heinrich Schuchardt <xypron.glpk@gmx.de>,
	Simon Glass <sjg@chromium.org>
Subject: [PATCH 2/3] dfu: dfu_fs: Simplify find_sector()
Date: Thu, 30 Sep 2021 18:22:07 +0200	[thread overview]
Message-ID: <20210930162208.2749155-2-frieder@fris.de> (raw)
In-Reply-To: <20210930162208.2749155-1-frieder@fris.de>

From: Frieder Schrempf <frieder.schrempf@kontron.de>

This doesn't include any functional changes, but simplifies the
existing code a bit and prepares for the following patch that
implements unaligned writes.

Signed-off-by: Frieder Schrempf <frieder.schrempf@kontron.de>
---
 drivers/dfu/dfu_sf.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/drivers/dfu/dfu_sf.c b/drivers/dfu/dfu_sf.c
index 7e64ab772f..c7ed674092 100644
--- a/drivers/dfu/dfu_sf.c
+++ b/drivers/dfu/dfu_sf.c
@@ -28,25 +28,24 @@ static int dfu_read_medium_sf(struct dfu_entity *dfu, u64 offset, void *buf,
 		*len, buf);
 }
 
-static u64 find_sector(struct dfu_entity *dfu, u64 start, u64 offset)
+static u64 find_sector(struct dfu_entity *dfu, u64 offset)
 {
-	return (lldiv((start + offset), dfu->data.sf.dev->sector_size)) *
+	return (lldiv(offset, dfu->data.sf.dev->sector_size)) *
 		dfu->data.sf.dev->sector_size;
 }
 
 static int dfu_write_medium_sf(struct dfu_entity *dfu,
 			       u64 offset, void *buf, long *len)
 {
+	u64 start = dfu->data.sf.start + offset;
 	int ret;
 
-	ret = spi_flash_erase(dfu->data.sf.dev,
-			      find_sector(dfu, dfu->data.sf.start, offset),
+	ret = spi_flash_erase(dfu->data.sf.dev, find_sector(dfu, start),
 			      dfu->data.sf.dev->sector_size);
 	if (ret)
 		return ret;
 
-	ret = spi_flash_write(dfu->data.sf.dev, dfu->data.sf.start + offset,
-			      *len, buf);
+	ret = spi_flash_write(dfu->data.sf.dev, start, *len, buf);
 	if (ret)
 		return ret;
 
@@ -61,7 +60,7 @@ static int dfu_flush_medium_sf(struct dfu_entity *dfu)
 		return 0;
 
 	/* in case of ubi partition, erase rest of the partition */
-	off = find_sector(dfu, dfu->data.sf.start, dfu->offset);
+	off = find_sector(dfu, dfu->data.sf.start + dfu->offset);
 	/* last write ended with unaligned length jump to next */
 	if (off != dfu->data.sf.start + dfu->offset)
 		off += dfu->data.sf.dev->sector_size;
-- 
2.33.0


  reply	other threads:[~2021-09-30 16:23 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-30 16:22 [PATCH 1/3] dfu: use pointer to pass length to dfu_write() Frieder Schrempf
2021-09-30 16:22 ` Frieder Schrempf [this message]
2021-09-30 16:22 ` [PATCH 3/3] dfu: dfu_sf: Support unaligned offsets for writing to serial flash Frieder Schrempf
2022-01-28 15:21 ` [PATCH 1/3] dfu: use pointer to pass length to dfu_write() Tom Rini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210930162208.2749155-2-frieder@fris.de \
    --to=frieder@fris.de \
    --cc=frieder.schrempf@kontron.de \
    --cc=heiko.thiery@gmail.com \
    --cc=lukma@denx.de \
    --cc=michael@walle.cc \
    --cc=sjg@chromium.org \
    --cc=u-boot@lists.denx.de \
    --cc=xypron.glpk@gmx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.