aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWarner Losh <imp@FreeBSD.org>2022-11-30 22:10:23 +0000
committerWarner Losh <imp@FreeBSD.org>2023-01-24 21:49:40 +0000
commit7ece24fe1680fe849667eab6ae4e84d93f364dbd (patch)
treed421ad3a726ecdfe87a05c80514b932c40bea134
parent6cb83949f7dd65d12e0baa5ee657ec8ebfc3233f (diff)
downloadsrc-7ece24fe1680fe849667eab6ae4e84d93f364dbd.tar.gz
src-7ece24fe1680fe849667eab6ae4e84d93f364dbd.zip
stand/ofw: Refactor ofw parsedev
Both ofw_disk and ofw_net use the same parsedev routine, except for the string passed in to match the ofw device node's type. Create a routine to do that and connect these two users up to that. Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D37560 (cherry picked from commit f9ce8da86434867e1e7172fb56a5504f91c98ce4)
-rw-r--r--stand/libofw/devicename.c23
-rw-r--r--stand/libofw/libofw.h2
-rw-r--r--stand/libofw/ofw_disk.c18
-rw-r--r--stand/libofw/ofw_net.c18
4 files changed, 27 insertions, 34 deletions
diff --git a/stand/libofw/devicename.c b/stand/libofw/devicename.c
index 7d488608c3f8..77a53ccd90ce 100644
--- a/stand/libofw/devicename.c
+++ b/stand/libofw/devicename.c
@@ -105,3 +105,26 @@ ofw_setcurrdev(struct env_var *ev, int flags, const void *value)
return (mount_currdev(ev, flags, value));
}
+
+int
+ofw_common_parsedev(struct devdesc **dev, const char *devspec, const char **path,
+ const char *ofwtype)
+{
+ const char *rem_path;
+ struct ofw_devdesc *idev;
+
+ if (ofw_path_to_handle(devspec, ofwtype, &rem_path) == -1)
+ return (ENOENT);
+ idev = malloc(sizeof(struct ofw_devdesc));
+ if (idev == NULL) {
+ printf("ofw_parsedev: malloc failed\n");
+ return ENOMEM;
+ };
+ strlcpy(idev->d_path, devspec, min(rem_path - devspec + 1,
+ sizeof(idev->d_path)));
+ if (dev != NULL)
+ *dev = &idev->dd;
+ if (path != NULL)
+ *path = rem_path;
+ return 0;
+}
diff --git a/stand/libofw/libofw.h b/stand/libofw/libofw.h
index ce7e6e986029..dc520d741290 100644
--- a/stand/libofw/libofw.h
+++ b/stand/libofw/libofw.h
@@ -63,6 +63,8 @@ extern int ofw_autoload(void);
void ofw_memmap(int);
phandle_t ofw_path_to_handle(const char *ofwpath, const char *want_type, const char **path);
+int ofw_common_parsedev(struct devdesc **dev, const char *devspec, const char **path,
+ const char *ofwtype);
struct preloaded_file;
struct file_format;
diff --git a/stand/libofw/ofw_disk.c b/stand/libofw/ofw_disk.c
index ae2776ee4689..ae36ca8be4b9 100644
--- a/stand/libofw/ofw_disk.c
+++ b/stand/libofw/ofw_disk.c
@@ -234,21 +234,5 @@ ofwd_fmtdev(struct devdesc *idev)
static int
ofwd_parsedev(struct devdesc **dev, const char *devspec, const char **path)
{
- const char *rem_path;
- struct ofw_devdesc *idev;
-
- if (ofw_path_to_handle(devspec, ofwdisk.dv_name, &rem_path) == -1)
- return (ENOENT);
- idev = malloc(sizeof(struct ofw_devdesc));
- if (idev == NULL) {
- printf("ofw_parsedev: malloc failed\n");
- return ENOMEM;
- };
- strlcpy(idev->d_path, devspec, min(rem_path - devspec + 1,
- sizeof(idev->d_path)));
- if (dev != NULL)
- *dev = &idev->dd;
- if (path != NULL)
- *path = rem_path;
- return 0;
+ return (ofw_common_parsedev(dev, devspec, path, ofwdisk.dv_name));
}
diff --git a/stand/libofw/ofw_net.c b/stand/libofw/ofw_net.c
index 59b9f8de7efb..0a2e7e2a8714 100644
--- a/stand/libofw/ofw_net.c
+++ b/stand/libofw/ofw_net.c
@@ -308,23 +308,7 @@ static int ofwnd_init(void)
static int
ofwnd_parsedev(struct devdesc **dev, const char *devspec, const char **path)
{
- const char *rem_path;
- struct ofw_devdesc *idev;
-
- if (ofw_path_to_handle(devspec, ofw_netdev.dv_name, &rem_path) == -1)
- return (ENOENT);
- idev = malloc(sizeof(struct ofw_devdesc));
- if (idev == NULL) {
- printf("ofw_parsedev: malloc failed\n");
- return ENOMEM;
- };
- strlcpy(idev->d_path, devspec, min(rem_path - devspec + 1,
- sizeof(idev->d_path)));
- if (dev != NULL)
- *dev = &idev->dd;
- if (path != NULL)
- *path = rem_path;
- return 0;
+ return (ofw_common_parsedev(dev, devspec, path, ofw_netdev.dv_name));
}
static bool