Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp4450966yba; Wed, 17 Apr 2019 11:46:19 -0700 (PDT) X-Google-Smtp-Source: APXvYqwGJeXNml69c+A7kdJV6eJRWKNSAHXOTrJ6giUzRI1aTjp1S7QhEzKgsyv1PKVpUfpRIN3B X-Received: by 2002:a65:51c8:: with SMTP id i8mr84256168pgq.175.1555526779340; Wed, 17 Apr 2019 11:46:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555526779; cv=none; d=google.com; s=arc-20160816; b=CAZ7fCIkzSsQIOYF2IlqTT5BAterNlOGpXN2aA6hGTz1Ek3CNqiT9OZY/SA4YyTqYi /hsYDX5p9coFoTBQ3GTMPv2NdVIJo8wNuIRNBmtjOtv5h+61/BZfU6ii29y6sQgSQvaV VoK4mcYil29Xu4lW7e5bH/2yriV52Tqz69ExickhGCh8CxiyAnnQzjsGW7B09BxuK4O9 1IOuaXiN4pzmljCfBx5hiZtIBl/STIO/0XVoem4IV8zkbtwc1X7Ojh60gswXcywwmFCq sarT9SPcNUXKGzMiHDJ30/QNuui9c2o7DBBR4StK8Klpc148sNkMI94/t/8qv6tdZunp 1FGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-disposition :mime-version:message-id:subject:cc:to:from:date; bh=z8RJ8U3h3nFVR3mcp7Jdsyfjh3+owNK3/2acKRssVyE=; b=OBSyp/VTL9UE3ZmidJTaRdFJswc058RRir4W9nr8zxcIGnoNR/aQ8/4dM3IkrlSPzT l3Spw6JHsc0hYb0kuSf4u2s0nz4DPwb8HRlUwlTDFkurvhvjZHPx1BiFH0YEu+6coqsr gfpD5+iums58yCImrhSoNWk2O+cDv2TFO38GhjsvwKWjVwsLroAae8Jo3p1QDQ7YSTyf dSjItAApi29g23va3NiopaR//KeQroMvg1ZRYkK7ht/T+E4oC2I3RovEdC61UtOyboBY VlH3UwUA0lDXfLAw5PtZGXH1ao+cw7OJAD3J4WyzRAwSH1h5wF6Cm6oEatslxBf+Rkhw Moeg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id gn14si38201931plb.7.2019.04.17.11.46.03; Wed, 17 Apr 2019 11:46:19 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732271AbfDQSop (ORCPT + 99 others); Wed, 17 Apr 2019 14:44:45 -0400 Received: from gateway23.websitewelcome.com ([192.185.47.80]:43058 "EHLO gateway23.websitewelcome.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727340AbfDQSop (ORCPT ); Wed, 17 Apr 2019 14:44:45 -0400 Received: from cm11.websitewelcome.com (cm11.websitewelcome.com [100.42.49.5]) by gateway23.websitewelcome.com (Postfix) with ESMTP id 160E9C385 for ; Wed, 17 Apr 2019 13:44:44 -0500 (CDT) Received: from gator4166.hostgator.com ([108.167.133.22]) by cmsmtp with SMTP id GpY3hnElndnCeGpY4hZv3M; Wed, 17 Apr 2019 13:44:44 -0500 X-Authority-Reason: nr=8 Received: from [189.250.55.242] (port=57756 helo=embeddedor) by gator4166.hostgator.com with esmtpa (Exim 4.91) (envelope-from ) id 1hGpY3-002nJj-0y; Wed, 17 Apr 2019 13:44:43 -0500 Date: Wed, 17 Apr 2019 13:44:40 -0500 From: "Gustavo A. R. Silva" To: Rui Miguel Silva , Johan Hovold , Alex Elder , Greg Kroah-Hartman Cc: greybus-dev@lists.linaro.org, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" Subject: [PATCH v2] staging: greybus: power_supply: use struct_size() helper Message-ID: <20190417184440.GA6025@embeddedor> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.9.4 (2018-02-28) X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator4166.hostgator.com X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - embeddedor.com X-BWhitelist: no X-Source-IP: 189.250.55.242 X-Source-L: No X-Exim-ID: 1hGpY3-002nJj-0y X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: (embeddedor) [189.250.55.242]:57756 X-Source-Auth: gustavo@embeddedor.com X-Email-Count: 7 X-Source-Cap: Z3V6aWRpbmU7Z3V6aWRpbmU7Z2F0b3I0MTY2Lmhvc3RnYXRvci5jb20= X-Local-Domain: yes Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Make use of the struct_size() helper instead of an open-coded version in order to avoid any potential type mistakes, in particular in the context in which this code is being used. So, replace code of the following form: sizeof(*resp) + props_count * sizeof(struct gb_power_supply_props_desc) with: struct_size(resp, props, props_count) This code was detected with the help of Coccinelle. Signed-off-by: Gustavo A. R. Silva --- Changes in v2: - Rebase on top of 47830c1127ef ("staging: greybus: power_supply: fix prop-descriptor request size") drivers/staging/greybus/power_supply.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/staging/greybus/power_supply.c b/drivers/staging/greybus/power_supply.c index ae5c0285a942..34b40a409ea3 100644 --- a/drivers/staging/greybus/power_supply.c +++ b/drivers/staging/greybus/power_supply.c @@ -520,8 +520,8 @@ static int gb_power_supply_prop_descriptors_get(struct gb_power_supply *gbpsy) op = gb_operation_create(connection, GB_POWER_SUPPLY_TYPE_GET_PROP_DESCRIPTORS, - sizeof(*req), sizeof(*resp) + props_count * - sizeof(struct gb_power_supply_props_desc), + sizeof(*req), + struct_size(resp, props, props_count), GFP_KERNEL); if (!op) return -ENOMEM; -- 2.21.0