summaryrefslogtreecommitdiff
path: root/net/iucv
diff options
context:
space:
mode:
authorHeiko Carstens <hca@linux.ibm.com>2024-05-06 21:44:49 +0200
committerAlexander Gordeev <agordeev@linux.ibm.com>2024-05-14 20:21:03 +0200
commit4452e8ef8c364113495f414d7e6846d74d7eff81 (patch)
treef1acd2784827dc06dfb3290c229277a8526c2c10 /net/iucv
parent1084562ec858d96c02d3a47d4afb088922f5a2ca (diff)
downloadlwn-4452e8ef8c364113495f414d7e6846d74d7eff81.tar.gz
lwn-4452e8ef8c364113495f414d7e6846d74d7eff81.zip
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 <arnd@arndb.de> Acked-by: Alexandra Winter <wintera@linux.ibm.com> Link: https://lore.kernel.org/r/20240506194454.1160315-2-hca@linux.ibm.com Signed-off-by: Heiko Carstens <hca@linux.ibm.com> Signed-off-by: Alexander Gordeev <agordeev@linux.ibm.com>
Diffstat (limited to 'net/iucv')
-rw-r--r--net/iucv/iucv.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
index a4ab615ca3e3..9db7c2c0ae72 100644
--- a/net/iucv/iucv.c
+++ b/net/iucv/iucv.c
@@ -76,6 +76,41 @@ EXPORT_SYMBOL(iucv_bus);
struct device *iucv_root;
EXPORT_SYMBOL(iucv_root);
+static void iucv_release_device(struct device *device)
+{
+ kfree(device);
+}
+
+struct device *iucv_alloc_device(const struct attribute_group **attrs,
+ struct device_driver *driver,
+ void *priv, const char *fmt, ...)
+{
+ struct device *dev;
+ va_list vargs;
+ int rc;
+
+ dev = kzalloc(sizeof(*dev), GFP_KERNEL);
+ if (!dev)
+ goto out_error;
+ va_start(vargs, fmt);
+ rc = dev_set_name(dev, fmt, vargs);
+ va_end(vargs);
+ if (rc)
+ goto out_error;
+ dev->bus = &iucv_bus;
+ dev->parent = iucv_root;
+ dev->driver = driver;
+ dev->groups = attrs;
+ dev->release = iucv_release_device;
+ dev_set_drvdata(dev, priv);
+ return dev;
+
+out_error:
+ kfree(dev);
+ return NULL;
+}
+EXPORT_SYMBOL(iucv_alloc_device);
+
static int iucv_available;
/* General IUCV interrupt structure */