diag: Allocate DCI memory using vzalloc instead of kzalloc
Currently there is a possibility of kmalloc failing when system is running low on memory condition. The patch changes the dci memory allocation from kzalloc to vzalloc. CRs-Fixed: 2195818 Change-Id: I92b20d8e77ce5b2a96212f9d0757fbbff2703891 Signed-off-by: Hardik Arya <harya@codeaurora.org>
This commit is contained in:
parent
c3b8576cf9
commit
4afc00eaff
1 changed files with 21 additions and 20 deletions
|
@ -26,6 +26,7 @@
|
||||||
#include <linux/reboot.h>
|
#include <linux/reboot.h>
|
||||||
#include <asm/current.h>
|
#include <asm/current.h>
|
||||||
#include <soc/qcom/restart.h>
|
#include <soc/qcom/restart.h>
|
||||||
|
#include <linux/vmalloc.h>
|
||||||
#ifdef CONFIG_DIAG_OVER_USB
|
#ifdef CONFIG_DIAG_OVER_USB
|
||||||
#include <linux/usb/usbdiag.h>
|
#include <linux/usb/usbdiag.h>
|
||||||
#endif
|
#endif
|
||||||
|
@ -258,7 +259,7 @@ static int diag_dci_init_buffer(struct diag_dci_buffer_t *buffer, int type)
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case DCI_BUF_PRIMARY:
|
case DCI_BUF_PRIMARY:
|
||||||
buffer->capacity = IN_BUF_SIZE;
|
buffer->capacity = IN_BUF_SIZE;
|
||||||
buffer->data = kzalloc(buffer->capacity, GFP_KERNEL);
|
buffer->data = vzalloc(buffer->capacity);
|
||||||
if (!buffer->data)
|
if (!buffer->data)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
break;
|
break;
|
||||||
|
@ -268,7 +269,7 @@ static int diag_dci_init_buffer(struct diag_dci_buffer_t *buffer, int type)
|
||||||
break;
|
break;
|
||||||
case DCI_BUF_CMD:
|
case DCI_BUF_CMD:
|
||||||
buffer->capacity = DIAG_MAX_REQ_SIZE + DCI_BUF_SIZE;
|
buffer->capacity = DIAG_MAX_REQ_SIZE + DCI_BUF_SIZE;
|
||||||
buffer->data = kzalloc(buffer->capacity, GFP_KERNEL);
|
buffer->data = vzalloc(buffer->capacity);
|
||||||
if (!buffer->data)
|
if (!buffer->data)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
break;
|
break;
|
||||||
|
@ -2719,7 +2720,7 @@ static int diag_dci_init_remote(void)
|
||||||
create_dci_event_mask_tbl(temp->event_mask_composite);
|
create_dci_event_mask_tbl(temp->event_mask_composite);
|
||||||
}
|
}
|
||||||
|
|
||||||
partial_pkt.data = kzalloc(MAX_DCI_PACKET_SZ, GFP_KERNEL);
|
partial_pkt.data = vzalloc(MAX_DCI_PACKET_SZ);
|
||||||
if (!partial_pkt.data) {
|
if (!partial_pkt.data) {
|
||||||
pr_err("diag: Unable to create partial pkt data\n");
|
pr_err("diag: Unable to create partial pkt data\n");
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
@ -2775,7 +2776,7 @@ int diag_dci_init(void)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
if (driver->apps_dci_buf == NULL) {
|
if (driver->apps_dci_buf == NULL) {
|
||||||
driver->apps_dci_buf = kzalloc(DCI_BUF_SIZE, GFP_KERNEL);
|
driver->apps_dci_buf = vzalloc(DCI_BUF_SIZE);
|
||||||
if (driver->apps_dci_buf == NULL)
|
if (driver->apps_dci_buf == NULL)
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
@ -2792,12 +2793,12 @@ int diag_dci_init(void)
|
||||||
return DIAG_DCI_NO_ERROR;
|
return DIAG_DCI_NO_ERROR;
|
||||||
err:
|
err:
|
||||||
pr_err("diag: Could not initialize diag DCI buffers");
|
pr_err("diag: Could not initialize diag DCI buffers");
|
||||||
kfree(driver->apps_dci_buf);
|
vfree(driver->apps_dci_buf);
|
||||||
driver->apps_dci_buf = NULL;
|
driver->apps_dci_buf = NULL;
|
||||||
|
|
||||||
if (driver->diag_dci_wq)
|
if (driver->diag_dci_wq)
|
||||||
destroy_workqueue(driver->diag_dci_wq);
|
destroy_workqueue(driver->diag_dci_wq);
|
||||||
kfree(partial_pkt.data);
|
vfree(partial_pkt.data);
|
||||||
partial_pkt.data = NULL;
|
partial_pkt.data = NULL;
|
||||||
mutex_destroy(&driver->dci_mutex);
|
mutex_destroy(&driver->dci_mutex);
|
||||||
mutex_destroy(&dci_log_mask_mutex);
|
mutex_destroy(&dci_log_mask_mutex);
|
||||||
|
@ -2817,9 +2818,9 @@ void diag_dci_channel_init(void)
|
||||||
|
|
||||||
void diag_dci_exit(void)
|
void diag_dci_exit(void)
|
||||||
{
|
{
|
||||||
kfree(partial_pkt.data);
|
vfree(partial_pkt.data);
|
||||||
partial_pkt.data = NULL;
|
partial_pkt.data = NULL;
|
||||||
kfree(driver->apps_dci_buf);
|
vfree(driver->apps_dci_buf);
|
||||||
driver->apps_dci_buf = NULL;
|
driver->apps_dci_buf = NULL;
|
||||||
mutex_destroy(&driver->dci_mutex);
|
mutex_destroy(&driver->dci_mutex);
|
||||||
mutex_destroy(&dci_log_mask_mutex);
|
mutex_destroy(&dci_log_mask_mutex);
|
||||||
|
@ -2959,7 +2960,7 @@ int diag_dci_register_client(struct diag_dci_reg_tbl_t *reg_entry)
|
||||||
new_entry->in_service = 0;
|
new_entry->in_service = 0;
|
||||||
INIT_LIST_HEAD(&new_entry->list_write_buf);
|
INIT_LIST_HEAD(&new_entry->list_write_buf);
|
||||||
mutex_init(&new_entry->write_buf_mutex);
|
mutex_init(&new_entry->write_buf_mutex);
|
||||||
new_entry->dci_log_mask = kzalloc(DCI_LOG_MASK_SIZE, GFP_KERNEL);
|
new_entry->dci_log_mask = vzalloc(DCI_LOG_MASK_SIZE);
|
||||||
if (!new_entry->dci_log_mask) {
|
if (!new_entry->dci_log_mask) {
|
||||||
pr_err("diag: Unable to create log mask for client, %d",
|
pr_err("diag: Unable to create log mask for client, %d",
|
||||||
driver->dci_client_id);
|
driver->dci_client_id);
|
||||||
|
@ -2967,7 +2968,7 @@ int diag_dci_register_client(struct diag_dci_reg_tbl_t *reg_entry)
|
||||||
}
|
}
|
||||||
create_dci_log_mask_tbl(new_entry->dci_log_mask, DCI_LOG_MASK_CLEAN);
|
create_dci_log_mask_tbl(new_entry->dci_log_mask, DCI_LOG_MASK_CLEAN);
|
||||||
|
|
||||||
new_entry->dci_event_mask = kzalloc(DCI_EVENT_MASK_SIZE, GFP_KERNEL);
|
new_entry->dci_event_mask = vzalloc(DCI_EVENT_MASK_SIZE);
|
||||||
if (!new_entry->dci_event_mask) {
|
if (!new_entry->dci_event_mask) {
|
||||||
pr_err("diag: Unable to create event mask for client, %d",
|
pr_err("diag: Unable to create event mask for client, %d",
|
||||||
driver->dci_client_id);
|
driver->dci_client_id);
|
||||||
|
@ -2977,7 +2978,7 @@ int diag_dci_register_client(struct diag_dci_reg_tbl_t *reg_entry)
|
||||||
|
|
||||||
new_entry->buffers = kzalloc(new_entry->num_buffers *
|
new_entry->buffers = kzalloc(new_entry->num_buffers *
|
||||||
sizeof(struct diag_dci_buf_peripheral_t),
|
sizeof(struct diag_dci_buf_peripheral_t),
|
||||||
GFP_KERNEL);
|
GFP_KERNEL);
|
||||||
if (!new_entry->buffers) {
|
if (!new_entry->buffers) {
|
||||||
pr_err("diag: Unable to allocate buffers for peripherals in %s\n",
|
pr_err("diag: Unable to allocate buffers for peripherals in %s\n",
|
||||||
__func__);
|
__func__);
|
||||||
|
@ -3001,7 +3002,7 @@ int diag_dci_register_client(struct diag_dci_reg_tbl_t *reg_entry)
|
||||||
if (!proc_buf->buf_primary)
|
if (!proc_buf->buf_primary)
|
||||||
goto fail_alloc;
|
goto fail_alloc;
|
||||||
proc_buf->buf_cmd = kzalloc(sizeof(struct diag_dci_buffer_t),
|
proc_buf->buf_cmd = kzalloc(sizeof(struct diag_dci_buffer_t),
|
||||||
GFP_KERNEL);
|
GFP_KERNEL);
|
||||||
if (!proc_buf->buf_cmd)
|
if (!proc_buf->buf_cmd)
|
||||||
goto fail_alloc;
|
goto fail_alloc;
|
||||||
err = diag_dci_init_buffer(proc_buf->buf_primary,
|
err = diag_dci_init_buffer(proc_buf->buf_primary,
|
||||||
|
@ -3034,7 +3035,7 @@ fail_alloc:
|
||||||
if (proc_buf) {
|
if (proc_buf) {
|
||||||
mutex_destroy(&proc_buf->health_mutex);
|
mutex_destroy(&proc_buf->health_mutex);
|
||||||
if (proc_buf->buf_primary) {
|
if (proc_buf->buf_primary) {
|
||||||
kfree(proc_buf->buf_primary->data);
|
vfree(proc_buf->buf_primary->data);
|
||||||
proc_buf->buf_primary->data = NULL;
|
proc_buf->buf_primary->data = NULL;
|
||||||
mutex_destroy(
|
mutex_destroy(
|
||||||
&proc_buf->buf_primary->data_mutex);
|
&proc_buf->buf_primary->data_mutex);
|
||||||
|
@ -3042,7 +3043,7 @@ fail_alloc:
|
||||||
kfree(proc_buf->buf_primary);
|
kfree(proc_buf->buf_primary);
|
||||||
proc_buf->buf_primary = NULL;
|
proc_buf->buf_primary = NULL;
|
||||||
if (proc_buf->buf_cmd) {
|
if (proc_buf->buf_cmd) {
|
||||||
kfree(proc_buf->buf_cmd->data);
|
vfree(proc_buf->buf_cmd->data);
|
||||||
proc_buf->buf_cmd->data = NULL;
|
proc_buf->buf_cmd->data = NULL;
|
||||||
mutex_destroy(
|
mutex_destroy(
|
||||||
&proc_buf->buf_cmd->data_mutex);
|
&proc_buf->buf_cmd->data_mutex);
|
||||||
|
@ -3051,9 +3052,9 @@ fail_alloc:
|
||||||
proc_buf->buf_cmd = NULL;
|
proc_buf->buf_cmd = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
kfree(new_entry->dci_event_mask);
|
vfree(new_entry->dci_event_mask);
|
||||||
new_entry->dci_event_mask = NULL;
|
new_entry->dci_event_mask = NULL;
|
||||||
kfree(new_entry->dci_log_mask);
|
vfree(new_entry->dci_log_mask);
|
||||||
new_entry->dci_log_mask = NULL;
|
new_entry->dci_log_mask = NULL;
|
||||||
kfree(new_entry->buffers);
|
kfree(new_entry->buffers);
|
||||||
new_entry->buffers = NULL;
|
new_entry->buffers = NULL;
|
||||||
|
@ -3088,7 +3089,7 @@ int diag_dci_deinit_client(struct diag_dci_client_tbl *entry)
|
||||||
* Clear the client's log and event masks, update the cumulative
|
* Clear the client's log and event masks, update the cumulative
|
||||||
* masks and send the masks to peripherals
|
* masks and send the masks to peripherals
|
||||||
*/
|
*/
|
||||||
kfree(entry->dci_log_mask);
|
vfree(entry->dci_log_mask);
|
||||||
entry->dci_log_mask = NULL;
|
entry->dci_log_mask = NULL;
|
||||||
diag_dci_invalidate_cumulative_log_mask(token);
|
diag_dci_invalidate_cumulative_log_mask(token);
|
||||||
if (token == DCI_LOCAL_PROC)
|
if (token == DCI_LOCAL_PROC)
|
||||||
|
@ -3097,7 +3098,7 @@ int diag_dci_deinit_client(struct diag_dci_client_tbl *entry)
|
||||||
if (ret != DIAG_DCI_NO_ERROR) {
|
if (ret != DIAG_DCI_NO_ERROR) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
kfree(entry->dci_event_mask);
|
vfree(entry->dci_event_mask);
|
||||||
entry->dci_event_mask = NULL;
|
entry->dci_event_mask = NULL;
|
||||||
diag_dci_invalidate_cumulative_event_mask(token);
|
diag_dci_invalidate_cumulative_event_mask(token);
|
||||||
if (token == DCI_LOCAL_PROC)
|
if (token == DCI_LOCAL_PROC)
|
||||||
|
@ -3161,12 +3162,12 @@ int diag_dci_deinit_client(struct diag_dci_client_tbl *entry)
|
||||||
}
|
}
|
||||||
|
|
||||||
mutex_lock(&proc_buf->buf_primary->data_mutex);
|
mutex_lock(&proc_buf->buf_primary->data_mutex);
|
||||||
kfree(proc_buf->buf_primary->data);
|
vfree(proc_buf->buf_primary->data);
|
||||||
proc_buf->buf_primary->data = NULL;
|
proc_buf->buf_primary->data = NULL;
|
||||||
mutex_unlock(&proc_buf->buf_primary->data_mutex);
|
mutex_unlock(&proc_buf->buf_primary->data_mutex);
|
||||||
|
|
||||||
mutex_lock(&proc_buf->buf_cmd->data_mutex);
|
mutex_lock(&proc_buf->buf_cmd->data_mutex);
|
||||||
kfree(proc_buf->buf_cmd->data);
|
vfree(proc_buf->buf_cmd->data);
|
||||||
proc_buf->buf_cmd->data = NULL;
|
proc_buf->buf_cmd->data = NULL;
|
||||||
mutex_unlock(&proc_buf->buf_cmd->data_mutex);
|
mutex_unlock(&proc_buf->buf_cmd->data_mutex);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue