dm ioctl: remove unnecessary check when using dm_get_mdptr()

Bugzilla: https://bugzilla.redhat.com/2179168
Upstream Status: kernel/git/torvalds/linux.git

commit a2f998a78a425edde5a1a1973c1d4854fe9d019f
Author: Hou Tao <houtao1@huawei.com>
Date:   Fri Dec 16 12:23:53 2022 +0800

    dm ioctl: remove unnecessary check when using dm_get_mdptr()

    __hash_remove() removes hash_cell with _hash_lock locked, so acquiring
    _hash_lock can guarantee no-NULL hc returned from dm_get_mdptr() must
    have not been removed and hc->md must still be md.

    __hash_remove() also acquires dm_hash_cells_mutex before setting mdptr
    as NULL. So in dm_copy_name_and_uuid(), after acquiring
    dm_hash_cells_mutex and ensuring returned hc is not NULL, the returned
    hc must still be alive and hc->md must still be md.

    Remove the unnecessary hc->md != md checks when using dm_get_mdptr()
    with _hash_lock or dm_hash_cells_mutex acquired.

    Signed-off-by: Hou Tao <houtao1@huawei.com>
    Signed-off-by: Mike Snitzer <snitzer@kernel.org>

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
This commit is contained in:
Benjamin Marzinski 2023-03-16 17:15:21 -05:00
parent 4412504f68
commit 28eec2befe
1 changed files with 3 additions and 3 deletions

View File

@ -789,7 +789,7 @@ static struct dm_table *dm_get_inactive_table(struct mapped_device *md, int *src
down_read(&_hash_lock);
hc = dm_get_mdptr(md);
if (!hc || hc->md != md) {
if (!hc) {
DMERR("device has been removed from the dev hash table.");
goto out;
}
@ -1500,7 +1500,7 @@ static int table_load(struct file *filp, struct dm_ioctl *param, size_t param_si
/* stage inactive table */
down_write(&_hash_lock);
hc = dm_get_mdptr(md);
if (!hc || hc->md != md) {
if (!hc) {
DMERR("device has been removed from the dev hash table.");
up_write(&_hash_lock);
r = -ENXIO;
@ -2152,7 +2152,7 @@ int dm_copy_name_and_uuid(struct mapped_device *md, char *name, char *uuid)
mutex_lock(&dm_hash_cells_mutex);
hc = dm_get_mdptr(md);
if (!hc || hc->md != md) {
if (!hc) {
r = -ENXIO;
goto out;
}