Skip to content

Commit 4452e8e

Browse files
hcahcaAlexander Gordeev
authored andcommitted
s390/iucv: Provide iucv_alloc_device() / iucv_release_device()
Provide iucv_alloc_device() and iucv_release_device() helper functions, which can be used to deduplicate more or less identical IUCV device allocation and release code in four different drivers. Suggested-by: Arnd Bergmann <[email protected]> Acked-by: Alexandra Winter <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Heiko Carstens <[email protected]> Signed-off-by: Alexander Gordeev <[email protected]>
1 parent 1084562 commit 4452e8e

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

include/net/iucv/iucv.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ struct iucv_array {
8484
extern const struct bus_type iucv_bus;
8585
extern struct device *iucv_root;
8686

87+
struct device_driver;
88+
89+
struct device *iucv_alloc_device(const struct attribute_group **attrs,
90+
struct device_driver *driver, void *priv,
91+
const char *fmt, ...) __printf(4, 5);
92+
8793
/*
8894
* struct iucv_path
8995
* pathid: 16 bit path identification

net/iucv/iucv.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,41 @@ EXPORT_SYMBOL(iucv_bus);
7676
struct device *iucv_root;
7777
EXPORT_SYMBOL(iucv_root);
7878

79+
static void iucv_release_device(struct device *device)
80+
{
81+
kfree(device);
82+
}
83+
84+
struct device *iucv_alloc_device(const struct attribute_group **attrs,
85+
struct device_driver *driver,
86+
void *priv, const char *fmt, ...)
87+
{
88+
struct device *dev;
89+
va_list vargs;
90+
int rc;
91+
92+
dev = kzalloc(sizeof(*dev), GFP_KERNEL);
93+
if (!dev)
94+
goto out_error;
95+
va_start(vargs, fmt);
96+
rc = dev_set_name(dev, fmt, vargs);
97+
va_end(vargs);
98+
if (rc)
99+
goto out_error;
100+
dev->bus = &iucv_bus;
101+
dev->parent = iucv_root;
102+
dev->driver = driver;
103+
dev->groups = attrs;
104+
dev->release = iucv_release_device;
105+
dev_set_drvdata(dev, priv);
106+
return dev;
107+
108+
out_error:
109+
kfree(dev);
110+
return NULL;
111+
}
112+
EXPORT_SYMBOL(iucv_alloc_device);
113+
79114
static int iucv_available;
80115

81116
/* General IUCV interrupt structure */

0 commit comments

Comments
 (0)