Skip to content

Commit

Permalink
misc: tifm: fix possible memory leak in tifm_7xx1_switch_media()
Browse files Browse the repository at this point in the history
[ Upstream commit fd2c930 ]

If device_register() returns error in tifm_7xx1_switch_media(),
name of kobject which is allocated in dev_set_name() called in device_add()
is leaked.

Never directly free @dev after calling device_register(), even
if it returned an error! Always use put_device() to give up the
reference initialized.

Fixes: 2428a8f ("tifm: move common device management tasks from tifm_7xx1 to tifm_core")
Signed-off-by: ruanjinjie <ruanjinjie@huawei.com>
Link: https://lore.kernel.org/r/20221117064725.3478402-1-ruanjinjie@huawei.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
ruanjinjie authored and gregkh committed Dec 31, 2022
1 parent 37a13b2 commit 848c459
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion drivers/misc/tifm_7xx1.c
Expand Up @@ -190,7 +190,7 @@ static void tifm_7xx1_switch_media(struct work_struct *work)
spin_unlock_irqrestore(&fm->lock, flags);
}
if (sock)
tifm_free_device(&sock->dev);
put_device(&sock->dev);
}
spin_lock_irqsave(&fm->lock, flags);
}
Expand Down

0 comments on commit 848c459

Please sign in to comment.