diff options
Diffstat (limited to 'drivers')
| -rw-r--r-- | drivers/lightnvm/core.c | 34 |
1 files changed, 16 insertions, 18 deletions
diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c index 0e9f7996ff1d..0df7454832ef 100644 --- a/drivers/lightnvm/core.c +++ b/drivers/lightnvm/core.c | |||
| @@ -483,7 +483,6 @@ static void __nvm_remove_target(struct nvm_target *t, bool graceful) | |||
| 483 | 483 | ||
| 484 | /** | 484 | /** |
| 485 | * nvm_remove_tgt - Removes a target from the media manager | 485 | * nvm_remove_tgt - Removes a target from the media manager |
| 486 | * @dev: device | ||
| 487 | * @remove: ioctl structure with target name to remove. | 486 | * @remove: ioctl structure with target name to remove. |
| 488 | * | 487 | * |
| 489 | * Returns: | 488 | * Returns: |
| @@ -491,18 +490,27 @@ static void __nvm_remove_target(struct nvm_target *t, bool graceful) | |||
| 491 | * 1: on not found | 490 | * 1: on not found |
| 492 | * <0: on error | 491 | * <0: on error |
| 493 | */ | 492 | */ |
| 494 | static int nvm_remove_tgt(struct nvm_dev *dev, struct nvm_ioctl_remove *remove) | 493 | static int nvm_remove_tgt(struct nvm_ioctl_remove *remove) |
| 495 | { | 494 | { |
| 496 | struct nvm_target *t; | 495 | struct nvm_target *t; |
| 496 | struct nvm_dev *dev; | ||
| 497 | 497 | ||
| 498 | mutex_lock(&dev->mlock); | 498 | down_read(&nvm_lock); |
| 499 | t = nvm_find_target(dev, remove->tgtname); | 499 | list_for_each_entry(dev, &nvm_devices, devices) { |
| 500 | if (!t) { | 500 | mutex_lock(&dev->mlock); |
| 501 | t = nvm_find_target(dev, remove->tgtname); | ||
| 502 | if (t) { | ||
| 503 | mutex_unlock(&dev->mlock); | ||
| 504 | break; | ||
| 505 | } | ||
| 501 | mutex_unlock(&dev->mlock); | 506 | mutex_unlock(&dev->mlock); |
| 502 | return 1; | ||
| 503 | } | 507 | } |
| 508 | up_read(&nvm_lock); | ||
| 509 | |||
| 510 | if (!t) | ||
| 511 | return 1; | ||
| 512 | |||
| 504 | __nvm_remove_target(t, true); | 513 | __nvm_remove_target(t, true); |
| 505 | mutex_unlock(&dev->mlock); | ||
| 506 | kref_put(&dev->ref, nvm_free); | 514 | kref_put(&dev->ref, nvm_free); |
| 507 | 515 | ||
| 508 | return 0; | 516 | return 0; |
| @@ -1348,8 +1356,6 @@ static long nvm_ioctl_dev_create(struct file *file, void __user *arg) | |||
| 1348 | static long nvm_ioctl_dev_remove(struct file *file, void __user *arg) | 1356 | static long nvm_ioctl_dev_remove(struct file *file, void __user *arg) |
| 1349 | { | 1357 | { |
| 1350 | struct nvm_ioctl_remove remove; | 1358 | struct nvm_ioctl_remove remove; |
| 1351 | struct nvm_dev *dev; | ||
| 1352 | int ret = 0; | ||
| 1353 | 1359 | ||
| 1354 | if (copy_from_user(&remove, arg, sizeof(struct nvm_ioctl_remove))) | 1360 | if (copy_from_user(&remove, arg, sizeof(struct nvm_ioctl_remove))) |
| 1355 | return -EFAULT; | 1361 | return -EFAULT; |
| @@ -1361,15 +1367,7 @@ static long nvm_ioctl_dev_remove(struct file *file, void __user *arg) | |||
| 1361 | return -EINVAL; | 1367 | return -EINVAL; |
| 1362 | } | 1368 | } |
| 1363 | 1369 | ||
| 1364 | down_read(&nvm_lock); | 1370 | return nvm_remove_tgt(&remove); |
| 1365 | list_for_each_entry(dev, &nvm_devices, devices) { | ||
| 1366 | ret = nvm_remove_tgt(dev, &remove); | ||
| 1367 | if (!ret) | ||
| 1368 | break; | ||
| 1369 | } | ||
| 1370 | up_read(&nvm_lock); | ||
| 1371 | |||
| 1372 | return ret; | ||
| 1373 | } | 1371 | } |
| 1374 | 1372 | ||
| 1375 | /* kept for compatibility reasons */ | 1373 | /* kept for compatibility reasons */ |
