Skip to content

Commit bdbb0a1

Browse files
htejungregkh
authored andcommitted
s390: use device_remove_file_self() instead of device_schedule_callback()
driver-core now supports synchrnous self-deletion of attributes and the asynchrnous removal mechanism is scheduled for removal. Use it instead of device_schedule_callback(). * Conversions in arch/s390/pci/pci_sysfs.c and drivers/s390/block/dcssblk.c are straightforward. * drivers/s390/cio/ccwgroup.c is a bit more tricky because ccwgroup_notifier() was (ab)using device_schedule_callback() to purely obtain a process context to kick off ungroup operation which may block from a notifier callback. Rename ccwgroup_ungroup_callback() to ccwgroup_ungroup() and make it take ccwgroup_device * instead. The new function is now called directly from ccwgroup_ungroup_store(). ccwgroup_notifier() chain is updated to explicitly bounce through ccwgroup_device->ungroup_work. This also removes possible failure from memory pressure. Only compile-tested. Signed-off-by: Tejun Heo <tj@kernel.org> Cc: Martin Schwidefsky <schwidefsky@de.ibm.com> Cc: Heiko Carstens <heiko.carstens@de.ibm.com> Cc: linux390@de.ibm.com Cc: linux-s390@vger.kernel.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent de1dee7 commit bdbb0a1

4 files changed

Lines changed: 32 additions & 27 deletions

File tree

‎arch/s390/include/asm/ccwgroup.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ struct ccwgroup_device {
2323
unsigned int count;
2424
struct device dev;
2525
struct ccw_device *cdev[0];
26+
struct work_struct ungroup_work;
2627
};
2728

2829
/**

‎arch/s390/pci/pci_sysfs.c‎

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,29 +48,27 @@ static ssize_t show_pfgid(struct device *dev, struct device_attribute *attr,
4848
}
4949
static DEVICE_ATTR(pfgid, S_IRUGO, show_pfgid, NULL);
5050

51-
static void recover_callback(struct device *dev)
51+
static ssize_t store_recover(struct device *dev, struct device_attribute *attr,
52+
const char *buf, size_t count)
5253
{
5354
struct pci_dev *pdev = to_pci_dev(dev);
5455
struct zpci_dev *zdev = get_zdev(pdev);
5556
int ret;
5657

58+
if (!device_remove_file_self(dev, attr))
59+
return count;
60+
5761
pci_stop_and_remove_bus_device(pdev);
5862
ret = zpci_disable_device(zdev);
5963
if (ret)
60-
return;
64+
return ret;
6165

6266
ret = zpci_enable_device(zdev);
6367
if (ret)
64-
return;
68+
return ret;
6569

6670
pci_rescan_bus(zdev->bus);
67-
}
68-
69-
static ssize_t store_recover(struct device *dev, struct device_attribute *attr,
70-
const char *buf, size_t count)
71-
{
72-
int rc = device_schedule_callback(dev, recover_callback);
73-
return rc ? rc : count;
71+
return count;
7472
}
7573
static DEVICE_ATTR(recover, S_IWUSR, NULL, store_recover);
7674

‎drivers/s390/block/dcssblk.c‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -304,12 +304,6 @@ dcssblk_load_segment(char *name, struct segment_info **seg_info)
304304
return rc;
305305
}
306306

307-
static void dcssblk_unregister_callback(struct device *dev)
308-
{
309-
device_unregister(dev);
310-
put_device(dev);
311-
}
312-
313307
/*
314308
* device attribute for switching shared/nonshared (exclusive)
315309
* operation (show + store)
@@ -397,7 +391,13 @@ dcssblk_shared_store(struct device *dev, struct device_attribute *attr, const ch
397391
blk_cleanup_queue(dev_info->dcssblk_queue);
398392
dev_info->gd->queue = NULL;
399393
put_disk(dev_info->gd);
400-
rc = device_schedule_callback(dev, dcssblk_unregister_callback);
394+
up_write(&dcssblk_devices_sem);
395+
396+
if (device_remove_file_self(dev, attr)) {
397+
device_unregister(dev);
398+
put_device(dev);
399+
}
400+
return rc;
401401
out:
402402
up_write(&dcssblk_devices_sem);
403403
return rc;

‎drivers/s390/cio/ccwgroup.c‎

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -168,14 +168,12 @@ static ssize_t ccwgroup_online_show(struct device *dev,
168168
* Provide an 'ungroup' attribute so the user can remove group devices no
169169
* longer needed or accidentially created. Saves memory :)
170170
*/
171-
static void ccwgroup_ungroup_callback(struct device *dev)
171+
static void ccwgroup_ungroup(struct ccwgroup_device *gdev)
172172
{
173-
struct ccwgroup_device *gdev = to_ccwgroupdev(dev);
174-
175173
mutex_lock(&gdev->reg_mutex);
176174
if (device_is_registered(&gdev->dev)) {
177175
__ccwgroup_remove_symlinks(gdev);
178-
device_unregister(dev);
176+
device_unregister(&gdev->dev);
179177
__ccwgroup_remove_cdev_refs(gdev);
180178
}
181179
mutex_unlock(&gdev->reg_mutex);
@@ -195,10 +193,9 @@ static ssize_t ccwgroup_ungroup_store(struct device *dev,
195193
rc = -EINVAL;
196194
goto out;
197195
}
198-
/* Note that we cannot unregister the device from one of its
199-
* attribute methods, so we have to use this roundabout approach.
200-
*/
201-
rc = device_schedule_callback(dev, ccwgroup_ungroup_callback);
196+
197+
if (device_remove_file_self(dev, attr))
198+
ccwgroup_ungroup(gdev);
202199
out:
203200
if (rc) {
204201
if (rc != -EAGAIN)
@@ -224,6 +221,14 @@ static const struct attribute_group *ccwgroup_attr_groups[] = {
224221
NULL,
225222
};
226223

224+
static void ccwgroup_ungroup_workfn(struct work_struct *work)
225+
{
226+
struct ccwgroup_device *gdev =
227+
container_of(work, struct ccwgroup_device, ungroup_work);
228+
229+
ccwgroup_ungroup(gdev);
230+
}
231+
227232
static void ccwgroup_release(struct device *dev)
228233
{
229234
kfree(to_ccwgroupdev(dev));
@@ -323,6 +328,7 @@ int ccwgroup_create_dev(struct device *parent, struct ccwgroup_driver *gdrv,
323328
atomic_set(&gdev->onoff, 0);
324329
mutex_init(&gdev->reg_mutex);
325330
mutex_lock(&gdev->reg_mutex);
331+
INIT_WORK(&gdev->ungroup_work, ccwgroup_ungroup_workfn);
326332
gdev->count = num_devices;
327333
gdev->dev.bus = &ccwgroup_bus_type;
328334
gdev->dev.parent = parent;
@@ -404,10 +410,10 @@ EXPORT_SYMBOL(ccwgroup_create_dev);
404410
static int ccwgroup_notifier(struct notifier_block *nb, unsigned long action,
405411
void *data)
406412
{
407-
struct device *dev = data;
413+
struct ccwgroup_device *gdev = to_ccwgroupdev(data);
408414

409415
if (action == BUS_NOTIFY_UNBIND_DRIVER)
410-
device_schedule_callback(dev, ccwgroup_ungroup_callback);
416+
schedule_work(&gdev->ungroup_work);
411417

412418
return NOTIFY_OK;
413419
}

0 commit comments

Comments
 (0)