Skip to content

Commit

Permalink
stm class: Fix module init return on allocation failure
Browse files Browse the repository at this point in the history
commit 927633a upstream.

In stm_heartbeat_init(): return value gets reset after the first
iteration by stm_source_register_device(), so allocation failures
after that will, after a clean up, return success. Fix that.

Fixes: 1192918 ("stm class: Add heartbeat stm source device")
Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Wang Hui <john.wanghui@huawei.com>
Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Link: https://lore.kernel.org/r/20210115195917.3184-2-alexander.shishkin@linux.intel.com
Cc: stable <stable@vger.kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Wang Hui authored and gregkh committed Jan 27, 2021
1 parent f583cce commit 225c87b
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions drivers/hwtracing/stm/heartbeat.c
Expand Up @@ -64,16 +64,18 @@ static void stm_heartbeat_unlink(struct stm_source_data *data)

static int stm_heartbeat_init(void)
{
int i, ret = -ENOMEM;
int i, ret;

if (nr_devs < 0 || nr_devs > STM_HEARTBEAT_MAX)
return -EINVAL;

for (i = 0; i < nr_devs; i++) {
stm_heartbeat[i].data.name =
kasprintf(GFP_KERNEL, "heartbeat.%d", i);
if (!stm_heartbeat[i].data.name)
if (!stm_heartbeat[i].data.name) {
ret = -ENOMEM;
goto fail_unregister;
}

stm_heartbeat[i].data.nr_chans = 1;
stm_heartbeat[i].data.link = stm_heartbeat_link;
Expand Down

0 comments on commit 225c87b

Please sign in to comment.