Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

visorbus: fix error return code in visorchipset_init()

Commit 1366a3db3dcf ("staging: unisys: visorbus: visorchipset_init clean
up gotos") assigns the initial value -ENODEV to the local variable 'err',
and the first several error branches will return this value after "goto
error". But commit f1f537c2e7f5 ("staging: unisys: visorbus: Consolidate
controlvm channel creation.") overwrites 'err' in the middle of the way.
As a result, some error branches do not successfully return the initial
value -ENODEV of 'err', but return 0.

In addition, when kzalloc() fails, -ENOMEM should be returned instead of
-ENODEV.

Fixes: f1f537c2e7f5 ("staging: unisys: visorbus: Consolidate controlvm channel creation.")
Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20210528082614.9337-1-thunder.leizhen@huawei.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Zhen Lei and committed by
Greg Kroah-Hartman
ce52ec5b cc196fed

+4 -2
+4 -2
drivers/visorbus/visorchipset.c
··· 1561 1561 1562 1562 static int visorchipset_init(struct acpi_device *acpi_device) 1563 1563 { 1564 - int err = -ENODEV; 1564 + int err = -ENOMEM; 1565 1565 struct visorchannel *controlvm_channel; 1566 1566 1567 1567 chipset_dev = kzalloc(sizeof(*chipset_dev), GFP_KERNEL); ··· 1584 1584 "controlvm", 1585 1585 sizeof(struct visor_controlvm_channel), 1586 1586 VISOR_CONTROLVM_CHANNEL_VERSIONID, 1587 - VISOR_CHANNEL_SIGNATURE)) 1587 + VISOR_CHANNEL_SIGNATURE)) { 1588 + err = -ENODEV; 1588 1589 goto error_delete_groups; 1590 + } 1589 1591 /* if booting in a crash kernel */ 1590 1592 if (is_kdump_kernel()) 1591 1593 INIT_DELAYED_WORK(&chipset_dev->periodic_controlvm_work,