Received: by 2002:a17:90a:b81:0:0:0:0 with SMTP id 1csp1017018pjr; Fri, 30 Aug 2019 11:16:38 -0700 (PDT) X-Google-Smtp-Source: APXvYqxe69917cRs4jTM2QdyC/52Bkds14kcWT08C9K3YKLidbErBF+DSHfmCE7ULoC6nqD+8jdC X-Received: by 2002:a17:90a:86c2:: with SMTP id y2mr17272925pjv.46.1567188998320; Fri, 30 Aug 2019 11:16:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567188998; cv=none; d=google.com; s=arc-20160816; b=lY8pKXiJLHGxsa+m8bv23eutcSZBfcMrYrtIxjm7QWiyOAE6twkhUjCwxSuPUkCtIw qGqLZ22WCuREAmfGw1yuiC7UEQJxYfJAsHvlMjjUf7fiwXPBcHF1ypcAhjV9sBDGxXKd B5PAtBgfxekVEe1w5UXYa2R8931spMFiUtgyIBt2WFtDTF9vZINpWN33U6ezwSwO6vUZ VW+GSJMSnuaRiaDma0IW3Dlpm+aOddL6Exjgil5Rssw2VKJcN7L/Kg3sTk449TdFXR/K /DoSPOIoztjWz64pG4ui66GC9Hbu2pdHG8ebOOWfze93ylS/M68Aj5CDPPMSbUUaLERP oRwQ== 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:dkim-signature; bh=FvxkqczR+A1t/cFp9JibpXsNBR3Ts73/K/qlmM3yxeo=; b=m2weFhj3TUPxpO25zhewZZvGEjUe6hrCHpcxuSwGbngWsPci7a9c4egHYZ0ukb7nXL uyxtAdHQCLRHD9g/IvgcB6YXrLk5Bu6iFKPqAVsc6MyEvVTQobLmZ+lsK7WcwUbUfOV4 Taqy9+2C+5siI4gxuFQAQ5sqZTiBDoySNNIEz51Hr6sbY0UkuGKdEksHKiPvqxbA0QMM JnUmAaZBA/mQu/Jq2Xu+hQhzVsS1hmsG7LxexFUidO37DYSk/Vtj/pcdcmaJ/YPtaZPS Uc7VC7qkYWd62qsD4lJMI3ELGQlKzvMkt39gbjrw+9Ww/QUqeBAAksjsvefb9M1zsQBO O1sw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@embeddedor.com header.s=default header.b=nHEwYYT1; 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 z1si1484099plb.347.2019.08.30.11.16.23; Fri, 30 Aug 2019 11:16:38 -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; dkim=fail header.i=@embeddedor.com header.s=default header.b=nHEwYYT1; 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 S1728309AbfH3SOx (ORCPT + 99 others); Fri, 30 Aug 2019 14:14:53 -0400 Received: from gateway24.websitewelcome.com ([192.185.51.56]:47200 "EHLO gateway24.websitewelcome.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727979AbfH3SOw (ORCPT ); Fri, 30 Aug 2019 14:14:52 -0400 Received: from cm13.websitewelcome.com (cm13.websitewelcome.com [100.42.49.6]) by gateway24.websitewelcome.com (Postfix) with ESMTP id DBEC85DC0F for ; Fri, 30 Aug 2019 13:14:50 -0500 (CDT) Received: from gator4166.hostgator.com ([108.167.133.22]) by cmsmtp with SMTP id 3lQAieMry3Qi03lQAiJHoY; Fri, 30 Aug 2019 13:14:50 -0500 X-Authority-Reason: nr=8 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=embeddedor.com; s=default; h=Content-Type:MIME-Version:Message-ID:Subject: Cc:To:From:Date:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=FvxkqczR+A1t/cFp9JibpXsNBR3Ts73/K/qlmM3yxeo=; b=nHEwYYT1ZkeN4QEQCXUjEiNKjH raYuW8hBKhZcskRrW+68HmzCeM+oYA8kDcPBggzJFy5/fMO2AwJJnDTdtQFdMY/ix7DcPiC6e6/12 MNwlv+8WKVm5wRyrxhSGZgYYSB9aFZPm69MPqujl6HO9EUmRObfHmNQLO1d2bLjFmnzJ6QksnMn0d WiUBdhJdSEp67TbI19BbW80Nz8pVdJRVTfPcvyx3mg8A+7NgXS+v/rbrPqxa0XKqoaV+L4uP/ReSG mehAvDJrfUvmc0D/3wAoMiLTLVCpjOZaT1lC2LRWHlApcOAWaULHQBqu1wJFaGFJL1hlbJ0F27Ccq 6A1lKYXw==; Received: from [189.152.216.116] (port=37172 helo=embeddedor) by gator4166.hostgator.com with esmtpa (Exim 4.92) (envelope-from ) id 1i3lQ9-001tMY-A8; Fri, 30 Aug 2019 13:14:49 -0500 Date: Fri, 30 Aug 2019 13:14:48 -0500 From: "Gustavo A. R. Silva" To: Jacek Anaszewski , Pavel Machek , Dan Murphy Cc: linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" , Kees Cook Subject: [PATCH] leds: is31fl32xx: Use struct_size() helper Message-ID: <20190830181448.GA24483@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.152.216.116 X-Source-L: No X-Exim-ID: 1i3lQ9-001tMY-A8 X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: (embeddedor) [189.152.216.116]:37172 X-Source-Auth: gustavo@embeddedor.com X-Email-Count: 5 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 One of the more common cases of allocation size calculations is finding the size of a structure that has a zero-sized array at the end, along with memory for some number of elements for that array. For example: struct is31fl32xx_priv { ... struct is31fl32xx_led_data leds[0]; }; Make use of the struct_size() helper instead of an open-coded version in order to avoid any potential type mistakes. So, replace the following function: static inline size_t sizeof_is31fl32xx_priv(int num_leds) { return sizeof(struct is31fl32xx_priv) + (sizeof(struct is31fl32xx_led_data) * num_leds); } with: struct_size(priv, leds, count) This code was detected with the help of Coccinelle. Signed-off-by: Gustavo A. R. Silva --- drivers/leds/leds-is31fl32xx.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/drivers/leds/leds-is31fl32xx.c b/drivers/leds/leds-is31fl32xx.c index 6fbab70dfb04..6f29b8943913 100644 --- a/drivers/leds/leds-is31fl32xx.c +++ b/drivers/leds/leds-is31fl32xx.c @@ -324,12 +324,6 @@ static int is31fl32xx_init_regs(struct is31fl32xx_priv *priv) return 0; } -static inline size_t sizeof_is31fl32xx_priv(int num_leds) -{ - return sizeof(struct is31fl32xx_priv) + - (sizeof(struct is31fl32xx_led_data) * num_leds); -} - static int is31fl32xx_parse_child_dt(const struct device *dev, const struct device_node *child, struct is31fl32xx_led_data *led_data) @@ -450,7 +444,7 @@ static int is31fl32xx_probe(struct i2c_client *client, if (!count) return -EINVAL; - priv = devm_kzalloc(dev, sizeof_is31fl32xx_priv(count), + priv = devm_kzalloc(dev, struct_size(priv, leds, count), GFP_KERNEL); if (!priv) return -ENOMEM; -- 2.23.0