Commit 4452e8ef authored by Heiko Carstens's avatar Heiko Carstens Committed by Alexander Gordeev

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: default avatarArnd Bergmann <arnd@arndb.de>
Acked-by: default avatarAlexandra Winter <wintera@linux.ibm.com>
Link: https://lore.kernel.org/r/20240506194454.1160315-2-hca@linux.ibm.comSigned-off-by: default avatarHeiko Carstens <hca@linux.ibm.com>
Signed-off-by: default avatarAlexander Gordeev <agordeev@linux.ibm.com>
parent 1084562e
...@@ -84,6 +84,12 @@ struct iucv_array { ...@@ -84,6 +84,12 @@ struct iucv_array {
extern const struct bus_type iucv_bus; extern const struct bus_type iucv_bus;
extern struct device *iucv_root; extern struct device *iucv_root;
struct device_driver;
struct device *iucv_alloc_device(const struct attribute_group **attrs,
struct device_driver *driver, void *priv,
const char *fmt, ...) __printf(4, 5);
/* /*
* struct iucv_path * struct iucv_path
* pathid: 16 bit path identification * pathid: 16 bit path identification
......
...@@ -76,6 +76,41 @@ EXPORT_SYMBOL(iucv_bus); ...@@ -76,6 +76,41 @@ EXPORT_SYMBOL(iucv_bus);
struct device *iucv_root; struct device *iucv_root;
EXPORT_SYMBOL(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; static int iucv_available;
/* General IUCV interrupt structure */ /* General IUCV interrupt structure */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment