[PATCH 08/13] fs: bpkfs: skip the data of ignored duplicates

Sascha Hauer s.hauer at pengutronix.de
Wed Nov 18 06:51:58 PST 2026


When a package holds the same type of image for the same hardware ID
more than once, bpkfs ignores all but the first. It forgets to seek
past the data of the ignored one though, so it reads the next data
header from that data instead, and mounting the package fails:

  bpkfs bpkfs0: ignore data 3 type kernel already present, ignored
  ERROR: bpkfs bpkfs0: could not seek: Invalid argument

Seek past the data before checking for duplicates, and free the name
of an ignored one, which leaked.

Fixes: 2f677b9b1ed5 ("fs: add BPKFS support")
Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 fs/bpkfs.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/fs/bpkfs.c b/fs/bpkfs.c
index 7908b13175..62d0229f8e 100644
--- a/fs/bpkfs.c
+++ b/fs/bpkfs.c
@@ -438,9 +438,19 @@ static int bpkfs_probe(struct device *dev)
 		offset += d->size;
 		size -= d->size;
 
+		/* to the next data header, also behind data that is ignored */
+		if (lseek(fd, d->size, SEEK_CUR) < 0) {
+			dev_err(dev, "could not seek: %m\n");
+			ret = -errno;
+			free(d->name);
+			free(d);
+			goto err;
+		}
+
 		if (bpkfs_get_by_type(priv, d->hw_id, d->type)) {
 			dev_info(dev, "ignore data %d type %s already present, ignored\n",
 				 i, type);
+			free(d->name);
 			free(d);
 			continue;
 		}
@@ -448,12 +458,6 @@ static int bpkfs_probe(struct device *dev)
 		list_add_tail(&d->list, &h->list_data);
 		priv->nb_data_entries++;
 
-		if (lseek(fd, d->size, SEEK_CUR) < 0) {
-			dev_err(dev, "could not seek: %m\n");
-			ret = -errno;
-			goto err;
-		}
-
 		type = d->name;
 		d = xzalloc(sizeof(*d));
 		d->type = be32_to_cpu(data_header.type);

-- 
2.47.3




More information about the barebox mailing list