Skip to content

Commit 9c53a17

Browse files
committed
xen: introduce xenbus_read_unsigned()
There are multiple instances of code reading an optional unsigned parameter from Xenstore via xenbus_scanf(). Instead of repeating the same code over and over add a service function doing the job. Signed-off-by: Juergen Gross <[email protected]> Reviewed-by: David Vrabel <[email protected]>
1 parent bc33b0c commit 9c53a17

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

drivers/xen/xenbus/xenbus_xs.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,21 @@ int xenbus_scanf(struct xenbus_transaction t,
559559
}
560560
EXPORT_SYMBOL_GPL(xenbus_scanf);
561561

562+
/* Read an (optional) unsigned value. */
563+
unsigned int xenbus_read_unsigned(const char *dir, const char *node,
564+
unsigned int default_val)
565+
{
566+
unsigned int val;
567+
int ret;
568+
569+
ret = xenbus_scanf(XBT_NIL, dir, node, "%u", &val);
570+
if (ret <= 0)
571+
val = default_val;
572+
573+
return val;
574+
}
575+
EXPORT_SYMBOL_GPL(xenbus_read_unsigned);
576+
562577
/* Single printf and write: returns -errno or 0. */
563578
int xenbus_printf(struct xenbus_transaction t,
564579
const char *dir, const char *node, const char *fmt, ...)

include/xen/xenbus.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ __scanf(4, 5)
151151
int xenbus_scanf(struct xenbus_transaction t,
152152
const char *dir, const char *node, const char *fmt, ...);
153153

154+
/* Read an (optional) unsigned value. */
155+
unsigned int xenbus_read_unsigned(const char *dir, const char *node,
156+
unsigned int default_val);
157+
154158
/* Single printf and write: returns -errno or 0. */
155159
__printf(4, 5)
156160
int xenbus_printf(struct xenbus_transaction t,

0 commit comments

Comments
 (0)