From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: oss-tools@pengutronix.de
Subject: [OSS-Tools] [PATCH v2 4/8] libdt: factor out __of_cdev_find helper
Date: Wed, 7 Jun 2023 14:16:24 +0200 [thread overview]
Message-ID: <20230607121628.3180139-5-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20230607121628.3180139-1-a.fatoum@pengutronix.de>
of_get_devicepath is an exported symbol by libdt, so we shouldn't change
its signature or its semantics. Yet, we will want to export more
information out of the udev'ification code in future. <dt/dt.h> already
declares an opaque struct cdev, so let's add a __of_cdev_find helper
that can populate it with the same information that of_get_devicepath
would return. In later commits we will define helpers that return
and process a struct cdev placed in dynamic memory.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
src/libdt.c | 82 +++++++++++++++++++++++++++++++++--------------------
1 file changed, 52 insertions(+), 30 deletions(-)
diff --git a/src/libdt.c b/src/libdt.c
index a4f0e256ef6a..c8a8ea43e452 100644
--- a/src/libdt.c
+++ b/src/libdt.c
@@ -32,6 +32,12 @@
#include <libudev.h>
#include <dt.h>
+struct cdev {
+ char *devpath;
+ off_t offset;
+ size_t size;
+};
+
static int pr_level = 5;
void pr_level_set(int level)
@@ -2482,33 +2488,14 @@ static struct udev_device *of_find_device_by_uuid(struct udev_device *parent,
return NULL;
}
-/*
- * of_get_devicepath - get information how to access device corresponding to a device_node
- * @partition_node: The device_node which shall be accessed
- * @devpath: Returns the devicepath under which the device is accessible
- * @offset: Returns the offset in the device
- * @size: Returns the size of the device
- *
- * This function takes a device_node which represents a partition.
- * For this partition the function returns the device path and the offset
- * and size in the device. For mtd devices the path will be /dev/mtdx, for
- * EEPROMs it will be /sys/.../eeprom and for block devices it will be /dev/...
- * For mtd devices the device path returned will be the partition itself.
- * Since EEPROMs do not have partitions under Linux @offset and @size will
- * describe the offset and size inside the full device. The same applies to
- * block devices.
- *
- * returns 0 for success or negative error value on failure.
- */
-int of_get_devicepath(struct device_node *partition_node, char **devpath, off_t *offset,
- size_t *size)
+static int __of_cdev_find(struct device_node *partition_node, struct cdev *cdev)
{
struct device_node *node;
struct udev_device *dev, *partdev, *mtd;
int ret;
- *offset = 0;
- *size = 0;
+ cdev->offset = 0;
+ cdev->size = 0;
/*
* simplest case: This nodepath can directly be translated into
@@ -2520,8 +2507,8 @@ int of_get_devicepath(struct device_node *partition_node, char **devpath, off_t
dev = of_find_device_by_node_path(partition_node->full_name);
if (dev) {
if (udev_device_is_eeprom(dev))
- return udev_parse_eeprom(dev, devpath);
- if (!udev_parse_mtd(dev, devpath, size))
+ return udev_parse_eeprom(dev, &cdev->devpath);
+ if (!udev_parse_mtd(dev, &cdev->devpath, &cdev->size))
return 0;
/*
@@ -2553,7 +2540,7 @@ int of_get_devicepath(struct device_node *partition_node, char **devpath, off_t
while (*uuid)
*s++ = tolower(*uuid++);
- *devpath = lc_uuid;
+ cdev->devpath = lc_uuid;
return 0;
}
@@ -2609,21 +2596,56 @@ int of_get_devicepath(struct device_node *partition_node, char **devpath, off_t
return -ENODEV;
/* ...find the desired information by mtd udev_device */
- return udev_parse_mtd(partdev, devpath, size);
+ return udev_parse_mtd(partdev, &cdev->devpath, &cdev->size);
}
if (udev_device_is_eeprom(dev)) {
- ret = udev_parse_eeprom(dev, devpath);
+ ret = udev_parse_eeprom(dev, &cdev->devpath);
if (ret)
return ret;
- return of_parse_partition(partition_node, offset, size);
+ return of_parse_partition(partition_node, &cdev->offset, &cdev->size);
} else {
- ret = device_find_block_device(dev, devpath);
+ ret = device_find_block_device(dev, &cdev->devpath);
if (ret)
return ret;
- return of_parse_partition(partition_node, offset, size);
+ return of_parse_partition(partition_node, &cdev->offset, &cdev->size);
}
return -EINVAL;
}
+
+/*
+ * of_get_devicepath - get information how to access device corresponding to a device_node
+ * @partition_node: The device_node which shall be accessed
+ * @devpath: Returns the devicepath under which the device is accessible
+ * @offset: Returns the offset in the device
+ * @size: Returns the size of the device
+ *
+ * This function takes a device_node which represents a partition.
+ * For this partition the function returns the device path and the offset
+ * and size in the device. For mtd devices the path will be /dev/mtdx, for
+ * EEPROMs it will be /sys/.../eeprom and for block devices it will be /dev/...
+ * For mtd devices the device path returned will be the partition itself.
+ * Since EEPROMs do not have partitions under Linux @offset and @size will
+ * describe the offset and size inside the full device. The same applies to
+ * block devices.
+ *
+ * returns 0 for success or negative error value on failure.
+ */
+int of_get_devicepath(struct device_node *partition_node, char **devpath, off_t *offset,
+ size_t *size)
+{
+ struct cdev cdev = {};
+ int ret;
+
+ ret = __of_cdev_find(partition_node, &cdev);
+ if (ret)
+ return ret;
+
+ *offset = cdev.offset;
+ *size = cdev.size;
+ *devpath = cdev.devpath;
+
+ return 0;
+}
--
2.39.2
next prev parent reply other threads:[~2023-06-07 12:16 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-07 12:16 [OSS-Tools] [PATCH v2 0/8] state: allow lookup of barebox state partition by Type GUID Ahmad Fatoum
2023-06-07 12:16 ` [OSS-Tools] [PATCH v2 1/8] state: backend: direct: open block device in read-only mode if possible Ahmad Fatoum
2023-06-07 12:16 ` [OSS-Tools] [PATCH v2 2/8] libdt: factor out u64 sysattr parsing into helper Ahmad Fatoum
2023-06-07 12:16 ` [OSS-Tools] [PATCH v2 3/8] libdt: drop broken if-branch Ahmad Fatoum
2023-06-07 12:16 ` Ahmad Fatoum [this message]
2023-06-07 12:16 ` [OSS-Tools] [PATCH v2 5/8] libdt: use block device partition instead of parent if found Ahmad Fatoum
2023-06-07 12:16 ` [OSS-Tools] [PATCH v2 6/8] state: align with barebox use of of_cdev_find Ahmad Fatoum
2023-06-07 12:16 ` [OSS-Tools] [PATCH v2 7/8] libdt: use of_find_device_by_uuid for partuuid lookup Ahmad Fatoum
2023-06-07 12:16 ` [OSS-Tools] [PATCH v2 8/8] state: allow lookup of barebox state partition by Type GUID Ahmad Fatoum
2023-06-12 11:52 ` [OSS-Tools] [PATCH v2 0/8] " Ahmad Fatoum
2023-07-03 12:23 ` Roland Hieber
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=20230607121628.3180139-5-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=oss-tools@pengutronix.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox