Commit 9cd67421 authored by Cornelia Huck's avatar Cornelia Huck Committed by Martin Schwidefsky

[S390] cio: Fix reference counting for online/offline.

The current code attempts to get an extra reference count
for online devices by doing a get_device() in ccw_device_online()
and a put_device() in ccw_device_done(). However, this
- incorrectly obtains an extra reference for disconnected
  devices becoming available again (since they are already
  online)
- needs special checks for css_init_done in order to handle
  the console device
- is not obvious and
- may incorretly drop a reference count in ccw_device_done() if
  that function is called after path verification for a device
  that just became not operational.

So let's just get the reference in ccw_device_set_online() and
drop it in ccw_device_set_offline(). (Unfortunately, we still
need the special case in io_subchannel_probe().)
Signed-off-by: default avatarCornelia Huck <cornelia.huck@de.ibm.com>
Signed-off-by: default avatarMartin Schwidefsky <schwidefsky@de.ibm.com>
parent 97166f52
...@@ -376,12 +376,16 @@ int ccw_device_set_offline(struct ccw_device *cdev) ...@@ -376,12 +376,16 @@ int ccw_device_set_offline(struct ccw_device *cdev)
dev_fsm_event(cdev, DEV_EVENT_NOTOPER); dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
} }
spin_unlock_irq(cdev->ccwlock); spin_unlock_irq(cdev->ccwlock);
/* Give up reference from ccw_device_set_online(). */
put_device(&cdev->dev);
return ret; return ret;
} }
spin_unlock_irq(cdev->ccwlock); spin_unlock_irq(cdev->ccwlock);
if (ret == 0) if (ret == 0) {
wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev)); wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev));
else { /* Give up reference from ccw_device_set_online(). */
put_device(&cdev->dev);
} else {
CIO_MSG_EVENT(0, "ccw_device_offline returned %d, " CIO_MSG_EVENT(0, "ccw_device_offline returned %d, "
"device 0.%x.%04x\n", "device 0.%x.%04x\n",
ret, cdev->private->dev_id.ssid, ret, cdev->private->dev_id.ssid,
...@@ -411,6 +415,9 @@ int ccw_device_set_online(struct ccw_device *cdev) ...@@ -411,6 +415,9 @@ int ccw_device_set_online(struct ccw_device *cdev)
return -ENODEV; return -ENODEV;
if (cdev->online || !cdev->drv) if (cdev->online || !cdev->drv)
return -EINVAL; return -EINVAL;
/* Hold on to an extra reference while device is online. */
if (!get_device(&cdev->dev))
return -ENODEV;
spin_lock_irq(cdev->ccwlock); spin_lock_irq(cdev->ccwlock);
ret = ccw_device_online(cdev); ret = ccw_device_online(cdev);
...@@ -422,10 +429,15 @@ int ccw_device_set_online(struct ccw_device *cdev) ...@@ -422,10 +429,15 @@ int ccw_device_set_online(struct ccw_device *cdev)
"device 0.%x.%04x\n", "device 0.%x.%04x\n",
ret, cdev->private->dev_id.ssid, ret, cdev->private->dev_id.ssid,
cdev->private->dev_id.devno); cdev->private->dev_id.devno);
/* Give up online reference since onlining failed. */
put_device(&cdev->dev);
return ret; return ret;
} }
if (cdev->private->state != DEV_STATE_ONLINE) if (cdev->private->state != DEV_STATE_ONLINE) {
/* Give up online reference since onlining failed. */
put_device(&cdev->dev);
return -ENODEV; return -ENODEV;
}
if (!cdev->drv->set_online || cdev->drv->set_online(cdev) == 0) { if (!cdev->drv->set_online || cdev->drv->set_online(cdev) == 0) {
cdev->online = 1; cdev->online = 1;
return 0; return 0;
...@@ -440,6 +452,8 @@ int ccw_device_set_online(struct ccw_device *cdev) ...@@ -440,6 +452,8 @@ int ccw_device_set_online(struct ccw_device *cdev)
"device 0.%x.%04x\n", "device 0.%x.%04x\n",
ret, cdev->private->dev_id.ssid, ret, cdev->private->dev_id.ssid,
cdev->private->dev_id.devno); cdev->private->dev_id.devno);
/* Give up online reference since onlining failed. */
put_device(&cdev->dev);
return (ret == 0) ? -ENODEV : ret; return (ret == 0) ? -ENODEV : ret;
} }
...@@ -1168,9 +1182,8 @@ static int io_subchannel_probe(struct subchannel *sch) ...@@ -1168,9 +1182,8 @@ static int io_subchannel_probe(struct subchannel *sch)
ccw_device_register(cdev); ccw_device_register(cdev);
/* /*
* Check if the device is already online. If it is * Check if the device is already online. If it is
* the reference count needs to be corrected * the reference count needs to be corrected since we
* (see ccw_device_online and css_init_done for the * didn't obtain a reference in ccw_device_set_online.
* ugly details).
*/ */
if (cdev->private->state != DEV_STATE_NOT_OPER && if (cdev->private->state != DEV_STATE_NOT_OPER &&
cdev->private->state != DEV_STATE_OFFLINE && cdev->private->state != DEV_STATE_OFFLINE &&
...@@ -1806,6 +1819,8 @@ ccw_device_remove (struct device *dev) ...@@ -1806,6 +1819,8 @@ ccw_device_remove (struct device *dev)
"device 0.%x.%04x\n", "device 0.%x.%04x\n",
ret, cdev->private->dev_id.ssid, ret, cdev->private->dev_id.ssid,
cdev->private->dev_id.devno); cdev->private->dev_id.devno);
/* Give up reference obtained in ccw_device_set_online(). */
put_device(&cdev->dev);
} }
ccw_device_set_timeout(cdev, 0); ccw_device_set_timeout(cdev, 0);
cdev->drv = NULL; cdev->drv = NULL;
......
...@@ -399,9 +399,6 @@ ccw_device_done(struct ccw_device *cdev, int state) ...@@ -399,9 +399,6 @@ ccw_device_done(struct ccw_device *cdev, int state)
ccw_device_oper_notify(cdev); ccw_device_oper_notify(cdev);
} }
wake_up(&cdev->private->wait_q); wake_up(&cdev->private->wait_q);
if (css_init_done && state != DEV_STATE_ONLINE)
put_device (&cdev->dev);
} }
static int cmp_pgid(struct pgid *p1, struct pgid *p2) static int cmp_pgid(struct pgid *p1, struct pgid *p2)
...@@ -611,8 +608,6 @@ ccw_device_online(struct ccw_device *cdev) ...@@ -611,8 +608,6 @@ ccw_device_online(struct ccw_device *cdev)
(cdev->private->state != DEV_STATE_BOXED)) (cdev->private->state != DEV_STATE_BOXED))
return -EINVAL; return -EINVAL;
sch = to_subchannel(cdev->dev.parent); sch = to_subchannel(cdev->dev.parent);
if (css_init_done && !get_device(&cdev->dev))
return -ENODEV;
ret = cio_enable_subchannel(sch, (u32)(addr_t)sch); ret = cio_enable_subchannel(sch, (u32)(addr_t)sch);
if (ret != 0) { if (ret != 0) {
/* Couldn't enable the subchannel for i/o. Sick device. */ /* Couldn't enable the subchannel for i/o. Sick device. */
......
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