Commit 789bba82 authored by Russ Weight's avatar Russ Weight Committed by Greg Kroah-Hartman
Browse files

firmware_loader: Fix memory leak in firmware upload



In the case of firmware-upload, an instance of struct fw_upload is
allocated in firmware_upload_register(). This data needs to be freed
in fw_dev_release(). Create a new fw_upload_free() function in
sysfs_upload.c to handle the firmware-upload specific memory frees
and incorporate the missing kfree call for the fw_upload structure.

Fixes: 97730bbb ("firmware_loader: Add firmware-upload support")
Cc: stable <stable@kernel.org>
Signed-off-by: default avatarRuss Weight <russell.h.weight@intel.com>
Link: https://lore.kernel.org/r/20220831002518.465274-1-russell.h.weight@intel.com


Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 8b40c38e
Loading
Loading
Loading
Loading
+3 −4
Original line number Diff line number Diff line
@@ -93,10 +93,9 @@ static void fw_dev_release(struct device *dev)
{
	struct fw_sysfs *fw_sysfs = to_fw_sysfs(dev);

	if (fw_sysfs->fw_upload_priv) {
		free_fw_priv(fw_sysfs->fw_priv);
		kfree(fw_sysfs->fw_upload_priv);
	}
	if (fw_sysfs->fw_upload_priv)
		fw_upload_free(fw_sysfs);

	kfree(fw_sysfs);
}

+5 −0
Original line number Diff line number Diff line
@@ -106,12 +106,17 @@ extern struct device_attribute dev_attr_cancel;
extern struct device_attribute dev_attr_remaining_size;

int fw_upload_start(struct fw_sysfs *fw_sysfs);
void fw_upload_free(struct fw_sysfs *fw_sysfs);
umode_t fw_upload_is_visible(struct kobject *kobj, struct attribute *attr, int n);
#else
static inline int fw_upload_start(struct fw_sysfs *fw_sysfs)
{
	return 0;
}

static inline void fw_upload_free(struct fw_sysfs *fw_sysfs)
{
}
#endif

#endif /* __FIRMWARE_SYSFS_H */
+9 −0
Original line number Diff line number Diff line
@@ -264,6 +264,15 @@ int fw_upload_start(struct fw_sysfs *fw_sysfs)
	return 0;
}

void fw_upload_free(struct fw_sysfs *fw_sysfs)
{
	struct fw_upload_priv *fw_upload_priv = fw_sysfs->fw_upload_priv;

	free_fw_priv(fw_sysfs->fw_priv);
	kfree(fw_upload_priv->fw_upload);
	kfree(fw_upload_priv);
}

/**
 * firmware_upload_register() - register for the firmware upload sysfs API
 * @module: kernel module of this device