Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/1110560/?format=api
{ "id": 1110560, "url": "http://patchwork.ozlabs.org/api/patches/1110560/?format=api", "web_url": "http://patchwork.ozlabs.org/project/intel-wired-lan/patch/20190605154052.GA7571@embeddedor/", "project": { "id": 46, "url": "http://patchwork.ozlabs.org/api/projects/46/?format=api", "name": "Intel Wired Ethernet development", "link_name": "intel-wired-lan", "list_id": "intel-wired-lan.osuosl.org", "list_email": "intel-wired-lan@osuosl.org", "web_url": "", "scm_url": "", "webscm_url": "", "list_archive_url": "", "list_archive_url_format": "", "commit_url_format": "" }, "msgid": "<20190605154052.GA7571@embeddedor>", "list_archive_url": null, "date": "2019-06-05T15:40:52", "name": "[next] i40e/i40e_virtchnl_pf: Use struct_size() in kzalloc()", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": false, "hash": "b25034b0fe86f11ea4c028935b6d450d6fcfd49c", "submitter": { "id": 72003, "url": "http://patchwork.ozlabs.org/api/people/72003/?format=api", "name": "Gustavo A. R. Silva", "email": "gustavo@embeddedor.com" }, "delegate": { "id": 68, "url": "http://patchwork.ozlabs.org/api/users/68/?format=api", "username": "jtkirshe", "first_name": "Jeff", "last_name": "Kirsher", "email": "jeffrey.t.kirsher@intel.com" }, "mbox": "http://patchwork.ozlabs.org/project/intel-wired-lan/patch/20190605154052.GA7571@embeddedor/mbox/", "series": [ { "id": 112000, "url": "http://patchwork.ozlabs.org/api/series/112000/?format=api", "web_url": "http://patchwork.ozlabs.org/project/intel-wired-lan/list/?series=112000", "date": "2019-06-05T15:40:52", "name": "[next] i40e/i40e_virtchnl_pf: Use struct_size() in kzalloc()", "version": 1, "mbox": "http://patchwork.ozlabs.org/series/112000/mbox/" } ], "comments": "http://patchwork.ozlabs.org/api/patches/1110560/comments/", "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/1110560/checks/", "tags": {}, "related": [], "headers": { "Return-Path": "<intel-wired-lan-bounces@osuosl.org>", "X-Original-To": [ "incoming@patchwork.ozlabs.org", "intel-wired-lan@lists.osuosl.org" ], "Delivered-To": [ "patchwork-incoming@bilbo.ozlabs.org", "intel-wired-lan@lists.osuosl.org" ], "Authentication-Results": [ "ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=osuosl.org\n\t(client-ip=140.211.166.133; helo=hemlock.osuosl.org;\n\tenvelope-from=intel-wired-lan-bounces@osuosl.org;\n\treceiver=<UNKNOWN>)", "ozlabs.org; dmarc=none (p=none dis=none)\n\theader.from=embeddedor.com" ], "Received": [ "from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n\tbits)) (No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 45Jtnb3PB0z9s3l\n\tfor <incoming@patchwork.ozlabs.org>;\n\tThu, 6 Jun 2019 02:01:22 +1000 (AEST)", "from localhost (localhost [127.0.0.1])\n\tby hemlock.osuosl.org (Postfix) with ESMTP id 7114487E9E;\n\tWed, 5 Jun 2019 16:01:20 +0000 (UTC)", "from hemlock.osuosl.org ([127.0.0.1])\n\tby localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024)\n\twith ESMTP id OxkvJz83RA0h; Wed, 5 Jun 2019 16:01:17 +0000 (UTC)", "from ash.osuosl.org (ash.osuosl.org [140.211.166.34])\n\tby hemlock.osuosl.org (Postfix) with ESMTP id 4E5BC86762;\n\tWed, 5 Jun 2019 16:01:17 +0000 (UTC)", "from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133])\n\tby ash.osuosl.org (Postfix) with ESMTP id 0A8041BF2B9\n\tfor <intel-wired-lan@lists.osuosl.org>;\n\tWed, 5 Jun 2019 16:01:16 +0000 (UTC)", "from localhost (localhost [127.0.0.1])\n\tby hemlock.osuosl.org (Postfix) with ESMTP id 067C486762\n\tfor <intel-wired-lan@lists.osuosl.org>;\n\tWed, 5 Jun 2019 16:01:16 +0000 (UTC)", "from hemlock.osuosl.org ([127.0.0.1])\n\tby localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024)\n\twith ESMTP id zZpyDPDBR2Qk for <intel-wired-lan@lists.osuosl.org>;\n\tWed, 5 Jun 2019 16:01:15 +0000 (UTC)", "from gateway21.websitewelcome.com (gateway21.websitewelcome.com\n\t[192.185.45.176])\n\tby hemlock.osuosl.org (Postfix) with ESMTPS id 301A38653F\n\tfor <intel-wired-lan@lists.osuosl.org>;\n\tWed, 5 Jun 2019 16:01:15 +0000 (UTC)", "from cm10.websitewelcome.com (cm10.websitewelcome.com\n\t[100.42.49.4])\n\tby gateway21.websitewelcome.com (Postfix) with ESMTP id 56846400C9F33\n\tfor <intel-wired-lan@lists.osuosl.org>;\n\tWed, 5 Jun 2019 10:40:55 -0500 (CDT)", "from gator4166.hostgator.com ([108.167.133.22]) by cmsmtp with SMTP\n\tid YY23hbNg12PzOYY23hvm2T; Wed, 05 Jun 2019 10:40:55 -0500", "from [189.250.127.120] (port=54884 helo=embeddedor)\n\tby gator4166.hostgator.com with esmtpa (Exim 4.91)\n\t(envelope-from <gustavo@embeddedor.com>)\n\tid 1hYY21-001MOH-RR; Wed, 05 Jun 2019 10:40:54 -0500" ], "X-Virus-Scanned": [ "amavisd-new at osuosl.org", "amavisd-new at osuosl.org" ], "X-Greylist": "delayed 00:20:19 by SQLgrey-1.7.6", "X-Authority-Reason": "nr=8", "Date": "Wed, 5 Jun 2019 10:40:52 -0500", "From": "\"Gustavo A. R. Silva\" <gustavo@embeddedor.com>", "To": "Jeff Kirsher <jeffrey.t.kirsher@intel.com>,\n\t\"David S. Miller\" <davem@davemloft.net>", "Message-ID": "<20190605154052.GA7571@embeddedor>", "MIME-Version": "1.0", "Content-Disposition": "inline", "User-Agent": "Mutt/1.9.4 (2018-02-28)", "X-AntiAbuse": [ "This header was added to track abuse,\n\tplease include it with any abuse report", "Primary Hostname - gator4166.hostgator.com", "Original Domain - lists.osuosl.org", "Originator/Caller UID/GID - [47 12] / [47 12]", "Sender Address Domain - embeddedor.com" ], "X-BWhitelist": "no", "X-Source-IP": "189.250.127.120", "X-Source-L": "No", "X-Exim-ID": "1hYY21-001MOH-RR", "X-Source": "", "X-Source-Args": "", "X-Source-Dir": "", "X-Source-Sender": "(embeddedor) [189.250.127.120]:54884", "X-Source-Auth": "gustavo@embeddedor.com", "X-Email-Count": "3", "X-Source-Cap": "Z3V6aWRpbmU7Z3V6aWRpbmU7Z2F0b3I0MTY2Lmhvc3RnYXRvci5jb20=", "X-Local-Domain": "yes", "Subject": "[Intel-wired-lan] [PATCH][next] i40e/i40e_virtchnl_pf: Use\n\tstruct_size() in kzalloc()", "X-BeenThere": "intel-wired-lan@osuosl.org", "X-Mailman-Version": "2.1.29", "Precedence": "list", "List-Id": "Intel Wired Ethernet Linux Kernel Driver Development\n\t<intel-wired-lan.osuosl.org>", "List-Unsubscribe": "<https://lists.osuosl.org/mailman/options/intel-wired-lan>, \n\t<mailto:intel-wired-lan-request@osuosl.org?subject=unsubscribe>", "List-Archive": "<http://lists.osuosl.org/pipermail/intel-wired-lan/>", "List-Post": "<mailto:intel-wired-lan@osuosl.org>", "List-Help": "<mailto:intel-wired-lan-request@osuosl.org?subject=help>", "List-Subscribe": "<https://lists.osuosl.org/mailman/listinfo/intel-wired-lan>, \n\t<mailto:intel-wired-lan-request@osuosl.org?subject=subscribe>", "Cc": "netdev@vger.kernel.org, intel-wired-lan@lists.osuosl.org,\n\tlinux-kernel@vger.kernel.org", "Content-Type": "text/plain; charset=\"us-ascii\"", "Content-Transfer-Encoding": "7bit", "Errors-To": "intel-wired-lan-bounces@osuosl.org", "Sender": "\"Intel-wired-lan\" <intel-wired-lan-bounces@osuosl.org>" }, "content": "One of the more common cases of allocation size calculations is finding\nthe size of a structure that has a zero-sized array at the end, along\nwith memory for some number of elements for that array. For example:\n\nstruct virtchnl_iwarp_qvlist_info {\n\t...\n struct virtchnl_iwarp_qv_info qv_info[1];\n};\n\nsize = sizeof(struct virtchnl_iwarp_qvlist_info) + (sizeof(struct virtchnl_iwarp_qv_info) * count;\ninstance = kzalloc(size, GFP_KERNEL);\n\nand\n\nstruct virtchnl_vf_resource {\n\t...\n struct virtchnl_vsi_resource vsi_res[1];\n};\n\nsize = sizeof(struct virtchnl_vf_resource) + sizeof(struct virtchnl_vsi_resource) * count;\ninstance = kzalloc(size, GFP_KERNEL);\n\nInstead of leaving these open-coded and prone to type mistakes, we can\nnow use the new struct_size() helper:\n\ninstance = kzalloc(struct_size(instance, qv_info, count), GFP_KERNEL);\n\nand\n\ninstance = kzalloc(struct_size(instance, vsi_res, count), GFP_KERNEL);\n\nNotice that, in the first case above, variable size is not necessary, hence it\nis removed.\n\nThis code was detected with the help of Coccinelle.\n\nSigned-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>\n---\n .../net/ethernet/intel/i40e/i40e_virtchnl_pf.c | 15 ++++++---------\n 1 file changed, 6 insertions(+), 9 deletions(-)", "diff": "diff --git a/drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c b/drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c\nindex 479bc60c8f71..1d6e65fc8a7e 100644\n--- a/drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c\n+++ b/drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c\n@@ -440,7 +440,7 @@ static int i40e_config_iwarp_qvlist(struct i40e_vf *vf,\n \tstruct virtchnl_iwarp_qv_info *qv_info;\n \tu32 v_idx, i, reg_idx, reg;\n \tu32 next_q_idx, next_q_type;\n-\tu32 msix_vf, size;\n+\tu32 msix_vf;\n \tint ret = 0;\n \n \tmsix_vf = pf->hw.func_caps.num_msix_vectors_vf;\n@@ -454,11 +454,10 @@ static int i40e_config_iwarp_qvlist(struct i40e_vf *vf,\n \t\tgoto err_out;\n \t}\n \n-\tsize = sizeof(struct virtchnl_iwarp_qvlist_info) +\n-\t (sizeof(struct virtchnl_iwarp_qv_info) *\n-\t\t\t\t\t\t(qvlist_info->num_vectors - 1));\n \tkfree(vf->qvlist_info);\n-\tvf->qvlist_info = kzalloc(size, GFP_KERNEL);\n+\tvf->qvlist_info = kzalloc(struct_size(vf->qvlist_info, qv_info,\n+\t\t\t\t\t qvlist_info->num_vectors - 1),\n+\t\t\t\t GFP_KERNEL);\n \tif (!vf->qvlist_info) {\n \t\tret = -ENOMEM;\n \t\tgoto err_out;\n@@ -1845,7 +1844,7 @@ static int i40e_vc_get_vf_resources_msg(struct i40e_vf *vf, u8 *msg)\n \ti40e_status aq_ret = 0;\n \tstruct i40e_vsi *vsi;\n \tint num_vsis = 1;\n-\tint len = 0;\n+\tsize_t len = 0;\n \tint ret;\n \n \tif (!test_bit(I40E_VF_STATE_INIT, &vf->vf_states)) {\n@@ -1853,9 +1852,7 @@ static int i40e_vc_get_vf_resources_msg(struct i40e_vf *vf, u8 *msg)\n \t\tgoto err;\n \t}\n \n-\tlen = (sizeof(struct virtchnl_vf_resource) +\n-\t sizeof(struct virtchnl_vsi_resource) * num_vsis);\n-\n+\tlen = struct_size(vfres, vsi_res, num_vsis);\n \tvfres = kzalloc(len, GFP_KERNEL);\n \tif (!vfres) {\n \t\taq_ret = I40E_ERR_NO_MEMORY;\n", "prefixes": [ "next" ] }