From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933217Ab1IHOGD (ORCPT ); Thu, 8 Sep 2011 10:06:03 -0400 Received: from p3plsmtps2ded03.prod.phx3.secureserver.net ([208.109.80.60]:40562 "HELO p3plsmtps2ded03-01.prod.phx3.secureserver.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S933079Ab1IHODP (ORCPT ); Thu, 8 Sep 2011 10:03:15 -0400 From: "K. Y. Srinivasan" To: gregkh@suse.de, linux-kernel@vger.kernel.org, devel@linuxdriverproject.org, virtualization@lists.osdl.org Cc: "K. Y. Srinivasan" , Haiyang Zhang Subject: [PATCH 22/25] Staging: hv: vmbus: Do not allocate struct hv_device_info on the stack Date: Thu, 8 Sep 2011 07:24:33 -0700 Message-Id: <1315491876-9554-22-git-send-email-kys@microsoft.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1315491876-9554-1-git-send-email-kys@microsoft.com> References: <1315491843-9513-1-git-send-email-kys@microsoft.com> <1315491876-9554-1-git-send-email-kys@microsoft.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org struct hv_device_info is about 101 bytes in size. Do not allocate this structure on the stack. Signed-off-by: K. Y. Srinivasan Signed-off-by: Haiyang Zhang --- drivers/staging/hv/vmbus_drv.c | 134 ++++++++++++++++++++------------------- 1 files changed, 69 insertions(+), 65 deletions(-) diff --git a/drivers/staging/hv/vmbus_drv.c b/drivers/staging/hv/vmbus_drv.c index 95d33a4..e39c92d 100644 --- a/drivers/staging/hv/vmbus_drv.c +++ b/drivers/staging/hv/vmbus_drv.c @@ -112,101 +112,105 @@ static ssize_t vmbus_show_device_attr(struct device *dev, char *buf) { struct hv_device *hv_dev = device_to_hv_device(dev); - struct hv_device_info device_info; + struct hv_device_info *device_info; char alias_name[VMBUS_ALIAS_LEN + 1]; + int ret = 0; - memset(&device_info, 0, sizeof(struct hv_device_info)); + device_info = kzalloc(sizeof(struct hv_device_info), GFP_KERNEL); + if (!device_info) + return ret; - get_channel_info(hv_dev, &device_info); + get_channel_info(hv_dev, device_info); if (!strcmp(dev_attr->attr.name, "class_id")) { - return sprintf(buf, "{%02x%02x%02x%02x-%02x%02x-%02x%02x-" + ret = sprintf(buf, "{%02x%02x%02x%02x-%02x%02x-%02x%02x-" "%02x%02x%02x%02x%02x%02x%02x%02x}\n", - device_info.chn_type.b[3], - device_info.chn_type.b[2], - device_info.chn_type.b[1], - device_info.chn_type.b[0], - device_info.chn_type.b[5], - device_info.chn_type.b[4], - device_info.chn_type.b[7], - device_info.chn_type.b[6], - device_info.chn_type.b[8], - device_info.chn_type.b[9], - device_info.chn_type.b[10], - device_info.chn_type.b[11], - device_info.chn_type.b[12], - device_info.chn_type.b[13], - device_info.chn_type.b[14], - device_info.chn_type.b[15]); + device_info->chn_type.b[3], + device_info->chn_type.b[2], + device_info->chn_type.b[1], + device_info->chn_type.b[0], + device_info->chn_type.b[5], + device_info->chn_type.b[4], + device_info->chn_type.b[7], + device_info->chn_type.b[6], + device_info->chn_type.b[8], + device_info->chn_type.b[9], + device_info->chn_type.b[10], + device_info->chn_type.b[11], + device_info->chn_type.b[12], + device_info->chn_type.b[13], + device_info->chn_type.b[14], + device_info->chn_type.b[15]); } else if (!strcmp(dev_attr->attr.name, "device_id")) { - return sprintf(buf, "{%02x%02x%02x%02x-%02x%02x-%02x%02x-" + ret = sprintf(buf, "{%02x%02x%02x%02x-%02x%02x-%02x%02x-" "%02x%02x%02x%02x%02x%02x%02x%02x}\n", - device_info.chn_instance.b[3], - device_info.chn_instance.b[2], - device_info.chn_instance.b[1], - device_info.chn_instance.b[0], - device_info.chn_instance.b[5], - device_info.chn_instance.b[4], - device_info.chn_instance.b[7], - device_info.chn_instance.b[6], - device_info.chn_instance.b[8], - device_info.chn_instance.b[9], - device_info.chn_instance.b[10], - device_info.chn_instance.b[11], - device_info.chn_instance.b[12], - device_info.chn_instance.b[13], - device_info.chn_instance.b[14], - device_info.chn_instance.b[15]); + device_info->chn_instance.b[3], + device_info->chn_instance.b[2], + device_info->chn_instance.b[1], + device_info->chn_instance.b[0], + device_info->chn_instance.b[5], + device_info->chn_instance.b[4], + device_info->chn_instance.b[7], + device_info->chn_instance.b[6], + device_info->chn_instance.b[8], + device_info->chn_instance.b[9], + device_info->chn_instance.b[10], + device_info->chn_instance.b[11], + device_info->chn_instance.b[12], + device_info->chn_instance.b[13], + device_info->chn_instance.b[14], + device_info->chn_instance.b[15]); } else if (!strcmp(dev_attr->attr.name, "modalias")) { print_alias_name(hv_dev, alias_name); - return sprintf(buf, "vmbus:%s\n", alias_name); + ret = sprintf(buf, "vmbus:%s\n", alias_name); } else if (!strcmp(dev_attr->attr.name, "state")) { - return sprintf(buf, "%d\n", device_info.chn_state); + ret = sprintf(buf, "%d\n", device_info->chn_state); } else if (!strcmp(dev_attr->attr.name, "id")) { - return sprintf(buf, "%d\n", device_info.chn_id); + ret = sprintf(buf, "%d\n", device_info->chn_id); } else if (!strcmp(dev_attr->attr.name, "out_intr_mask")) { - return sprintf(buf, "%d\n", device_info.outbound.int_mask); + ret = sprintf(buf, "%d\n", device_info->outbound.int_mask); } else if (!strcmp(dev_attr->attr.name, "out_read_index")) { - return sprintf(buf, "%d\n", device_info.outbound.read_idx); + ret = sprintf(buf, "%d\n", device_info->outbound.read_idx); } else if (!strcmp(dev_attr->attr.name, "out_write_index")) { - return sprintf(buf, "%d\n", device_info.outbound.write_idx); + ret = sprintf(buf, "%d\n", device_info->outbound.write_idx); } else if (!strcmp(dev_attr->attr.name, "out_read_bytes_avail")) { - return sprintf(buf, "%d\n", - device_info.outbound.bytes_avail_toread); + ret = sprintf(buf, "%d\n", + device_info->outbound.bytes_avail_toread); } else if (!strcmp(dev_attr->attr.name, "out_write_bytes_avail")) { - return sprintf(buf, "%d\n", - device_info.outbound.bytes_avail_towrite); + ret = sprintf(buf, "%d\n", + device_info->outbound.bytes_avail_towrite); } else if (!strcmp(dev_attr->attr.name, "in_intr_mask")) { - return sprintf(buf, "%d\n", device_info.inbound.int_mask); + ret = sprintf(buf, "%d\n", device_info->inbound.int_mask); } else if (!strcmp(dev_attr->attr.name, "in_read_index")) { - return sprintf(buf, "%d\n", device_info.inbound.read_idx); + ret = sprintf(buf, "%d\n", device_info->inbound.read_idx); } else if (!strcmp(dev_attr->attr.name, "in_write_index")) { - return sprintf(buf, "%d\n", device_info.inbound.write_idx); + ret = sprintf(buf, "%d\n", device_info->inbound.write_idx); } else if (!strcmp(dev_attr->attr.name, "in_read_bytes_avail")) { - return sprintf(buf, "%d\n", - device_info.inbound.bytes_avail_toread); + ret = sprintf(buf, "%d\n", + device_info->inbound.bytes_avail_toread); } else if (!strcmp(dev_attr->attr.name, "in_write_bytes_avail")) { - return sprintf(buf, "%d\n", - device_info.inbound.bytes_avail_towrite); + ret = sprintf(buf, "%d\n", + device_info->inbound.bytes_avail_towrite); } else if (!strcmp(dev_attr->attr.name, "monitor_id")) { - return sprintf(buf, "%d\n", device_info.monitor_id); + ret = sprintf(buf, "%d\n", device_info->monitor_id); } else if (!strcmp(dev_attr->attr.name, "server_monitor_pending")) { - return sprintf(buf, "%d\n", device_info.server_monitor_pending); + ret = sprintf(buf, "%d\n", device_info->server_monitor_pending); } else if (!strcmp(dev_attr->attr.name, "server_monitor_latency")) { - return sprintf(buf, "%d\n", device_info.server_monitor_latency); + ret = sprintf(buf, "%d\n", device_info->server_monitor_latency); } else if (!strcmp(dev_attr->attr.name, "server_monitor_conn_id")) { - return sprintf(buf, "%d\n", - device_info.server_monitor_conn_id); + ret = sprintf(buf, "%d\n", + device_info->server_monitor_conn_id); } else if (!strcmp(dev_attr->attr.name, "client_monitor_pending")) { - return sprintf(buf, "%d\n", device_info.client_monitor_pending); + ret = sprintf(buf, "%d\n", device_info->client_monitor_pending); } else if (!strcmp(dev_attr->attr.name, "client_monitor_latency")) { - return sprintf(buf, "%d\n", device_info.client_monitor_latency); + ret = sprintf(buf, "%d\n", device_info->client_monitor_latency); } else if (!strcmp(dev_attr->attr.name, "client_monitor_conn_id")) { - return sprintf(buf, "%d\n", - device_info.client_monitor_conn_id); - } else { - return 0; + ret = sprintf(buf, "%d\n", + device_info->client_monitor_conn_id); } + + kfree(device_info); + return ret; } /* Set up per device attributes in /sys/bus/vmbus/devices/ */ -- 1.7.4.1