Skip to content

Commit

Permalink
qcacld-3.0: Fix memory leak in driver dump
Browse files Browse the repository at this point in the history
Currently when driver gets a command to dump the
driver info, it allocates the memory and retrieves
the information in that allocated memory. Maximum data
that can be copied to user space buffer is equal to
one PAGE_SIZE. In the command driver gets the size of
the data which user space wants to read, minimum of the
user space requested size or one PAGE_SIZE of the data
is copied to user space buffer and current position of
the driver buffer till which the data is copied is
updated to user space is also updated.

Driver copies the retrieved information to the user
space buffer as explained above and updates the position
pointer to the user space. In the next request driver
expects from user space to request the remaining data
from the updated position in last request, once all the
data is copied to user space, driver frees internally
allocated memory.

In case if driver does not get the request to read
remaining data after first request, it does not free
the memory. Current handling of this memory is done
in init domain after stop modules, but since this
memory is allocated in active domain, driver should free
the memory in active domain.
Since with current implementation memory allocated in
active domain is not freed in active domain, memleak is
getting detected.

To resolve above issue, move mem cleanup logic for
driver dump info command from init domain to active domain in stop
modules.

Change-Id: Idb4f35f0a599ad55eebe13348b68562fa401fd7e
CRs-Fixed: 2489877
  • Loading branch information
Ashish Kumar Dhanotiya authored and nshrivas committed Jul 30, 2019
1 parent 09c63a7 commit aba3b97
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
15 changes: 15 additions & 0 deletions core/hdd/inc/wlan_hdd_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -3436,6 +3436,17 @@ void hdd_component_psoc_disable(struct wlan_objmgr_psoc *psoc);
#ifdef WLAN_FEATURE_MEMDUMP_ENABLE
int hdd_driver_memdump_init(void);
void hdd_driver_memdump_deinit(void);

/**
* hdd_driver_mem_cleanup() - Frees memory allocated for
* driver dump
*
* This function frees driver dump memory.
*
* Return: None
*/
void hdd_driver_mem_cleanup(void);

#else /* WLAN_FEATURE_MEMDUMP_ENABLE */
static inline int hdd_driver_memdump_init(void)
{
Expand All @@ -3444,6 +3455,10 @@ static inline int hdd_driver_memdump_init(void)
static inline void hdd_driver_memdump_deinit(void)
{
}

static inline void hdd_driver_mem_cleanup(void)
{
}
#endif /* WLAN_FEATURE_MEMDUMP_ENABLE */
/**
* hdd_set_disconnect_status() - set adapter disconnection status
Expand Down
1 change: 1 addition & 0 deletions core/hdd/src/wlan_hdd_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -11781,6 +11781,7 @@ int hdd_wlan_stop_modules(struct hdd_context *hdd_ctx, bool ftm_mode)

/* Free the cache channels of the command SET_DISABLE_CHANNEL_LIST */
wlan_hdd_free_cache_channels(hdd_ctx);
hdd_driver_mem_cleanup();

/* Free the resources allocated while storing SAR config. These needs
* to be freed only in the case when it is not SSR. As in the case of
Expand Down
12 changes: 1 addition & 11 deletions core/hdd/src/wlan_hdd_memdump.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,7 @@ static void *memdump_get_file_data(struct file *file)
return hdd_ctx;
}

/**
* hdd_driver_mem_cleanup() - Frees memory allocated for
* driver dump
*
* This function unallocates driver dump memory.
*
* Return: None
*/
static void hdd_driver_mem_cleanup(void)
void hdd_driver_mem_cleanup(void)
{
struct hdd_context *hdd_ctx;

Expand Down Expand Up @@ -305,6 +297,4 @@ int hdd_driver_memdump_init(void)
void hdd_driver_memdump_deinit(void)
{
hdd_driver_memdump_procfs_remove();

hdd_driver_mem_cleanup();
}

0 comments on commit aba3b97

Please sign in to comment.