From: Luis R. Rodriguez Date: Sat, 10 Mar 2018 14:14:56 +0000 (-0800) Subject: firmware: fix checking for return values for fw_add_devm_name() X-Git-Tag: Ubuntu-4.15.0-34.37~19 X-Git-Url: https://git.proxmox.com/?p=mirror_ubuntu-bionic-kernel.git;a=commitdiff_plain;h=62e667f97188f147028ae88f8606d8b62bd13462 firmware: fix checking for return values for fw_add_devm_name() BugLink: http://bugs.launchpad.net/bugs/1786352 [ Upstream commit d15d7311550983be97dca44ad68cbc2ca001297b ] Currently fw_add_devm_name() returns 1 if the firmware cache was already set. This makes it complicated for us to check for correctness. It is actually non-fatal if the firmware cache is already setup, so just return 0, and simplify the checkers. fw_add_devm_name() adds device's name onto the devres for the device so that prior to suspend we cache the firmware onto memory, so that on resume the firmware is reliably available. We never were checking for success for this call though, meaning in some really rare cases we my have never setup the firmware cache for a device, which could in turn make resume fail. This is all theoretical, no known issues have been reported. This small issue has been present way since the addition of the devres firmware cache names on v3.7. Fixes: f531f05ae9437 ("firmware loader: store firmware name into devres list") Signed-off-by: Luis R. Rodriguez Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman Signed-off-by: Kamal Mostafa Signed-off-by: Khalid Elmously --- diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c index 4b57cf5bc81d..0e7426814416 100644 --- a/drivers/base/firmware_class.c +++ b/drivers/base/firmware_class.c @@ -499,7 +499,7 @@ static int fw_add_devm_name(struct device *dev, const char *name) fwn = fw_find_devm_name(dev, name); if (fwn) - return 1; + return 0; fwn = devres_alloc(fw_name_devm_release, sizeof(struct fw_name_devm), GFP_KERNEL); @@ -527,6 +527,7 @@ static int assign_firmware_buf(struct firmware *fw, struct device *device, unsigned int opt_flags) { struct firmware_buf *buf = fw->priv; + int ret; mutex_lock(&fw_lock); if (!buf->size || fw_state_is_aborted(&buf->fw_st)) { @@ -543,8 +544,13 @@ static int assign_firmware_buf(struct firmware *fw, struct device *device, */ /* don't cache firmware handled without uevent */ if (device && (opt_flags & FW_OPT_UEVENT) && - !(opt_flags & FW_OPT_NOCACHE)) - fw_add_devm_name(device, buf->fw_id); + !(opt_flags & FW_OPT_NOCACHE)) { + ret = fw_add_devm_name(device, buf->fw_id); + if (ret) { + mutex_unlock(&fw_lock); + return ret; + } + } /* * After caching firmware image is started, let it piggyback