Skip to content

Commit 789bba8

Browse files
Russ Weightgregkh
authored andcommitted
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: 97730bb ("firmware_loader: Add firmware-upload support") Cc: stable <[email protected]> Signed-off-by: Russ Weight <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 8b40c38 commit 789bba8

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

drivers/base/firmware_loader/sysfs.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,9 @@ static void fw_dev_release(struct device *dev)
9393
{
9494
struct fw_sysfs *fw_sysfs = to_fw_sysfs(dev);
9595

96-
if (fw_sysfs->fw_upload_priv) {
97-
free_fw_priv(fw_sysfs->fw_priv);
98-
kfree(fw_sysfs->fw_upload_priv);
99-
}
96+
if (fw_sysfs->fw_upload_priv)
97+
fw_upload_free(fw_sysfs);
98+
10099
kfree(fw_sysfs);
101100
}
102101

drivers/base/firmware_loader/sysfs.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,17 @@ extern struct device_attribute dev_attr_cancel;
106106
extern struct device_attribute dev_attr_remaining_size;
107107

108108
int fw_upload_start(struct fw_sysfs *fw_sysfs);
109+
void fw_upload_free(struct fw_sysfs *fw_sysfs);
109110
umode_t fw_upload_is_visible(struct kobject *kobj, struct attribute *attr, int n);
110111
#else
111112
static inline int fw_upload_start(struct fw_sysfs *fw_sysfs)
112113
{
113114
return 0;
114115
}
116+
117+
static inline void fw_upload_free(struct fw_sysfs *fw_sysfs)
118+
{
119+
}
115120
#endif
116121

117122
#endif /* __FIRMWARE_SYSFS_H */

drivers/base/firmware_loader/sysfs_upload.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,15 @@ int fw_upload_start(struct fw_sysfs *fw_sysfs)
264264
return 0;
265265
}
266266

267+
void fw_upload_free(struct fw_sysfs *fw_sysfs)
268+
{
269+
struct fw_upload_priv *fw_upload_priv = fw_sysfs->fw_upload_priv;
270+
271+
free_fw_priv(fw_sysfs->fw_priv);
272+
kfree(fw_upload_priv->fw_upload);
273+
kfree(fw_upload_priv);
274+
}
275+
267276
/**
268277
* firmware_upload_register() - register for the firmware upload sysfs API
269278
* @module: kernel module of this device

0 commit comments

Comments
 (0)