From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gateway30.websitewelcome.com ([192.185.148.2]:33937 "EHLO gateway30.websitewelcome.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726145AbeHXCSi (ORCPT ); Thu, 23 Aug 2018 22:18:38 -0400 Received: from cm17.websitewelcome.com (cm17.websitewelcome.com [100.42.49.20]) by gateway30.websitewelcome.com (Postfix) with ESMTP id 5CF74D886 for ; Thu, 23 Aug 2018 17:01:26 -0500 (CDT) Subject: Re: [PATCH] rtc: sun6i: Use struct_size() in kzalloc() To: Kees Cook Cc: Alessandro Zummo , Alexandre Belloni , Maxime Ripard , Chen-Yu Tsai , linux-rtc@vger.kernel.org, linux-arm-kernel , LKML References: <20180823185140.GA29028@embeddedor.com> From: "Gustavo A. R. Silva" Message-ID: <7a213f7c-354c-06d5-7b14-fc69e9bb8a31@embeddedor.com> Date: Thu, 23 Aug 2018 17:01:11 -0500 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Sender: linux-rtc-owner@vger.kernel.org List-ID: On 8/23/18 3:56 PM, Kees Cook wrote: >> >> - clk_data = kzalloc(sizeof(*clk_data) + (sizeof(*clk_data->hws) * 2), >> - GFP_KERNEL); >> + clk_data = kzalloc(struct_size(clk_data, hws, 2), GFP_KERNEL); >> if (!clk_data) { >> kfree(rtc); >> return; > > This looks like entirely correct to me, but I'm surprised the > Coccinelle script didn't discover this. I guess the isomorphisms don't > cover the parenthesis? > Apparently. If I manually remove the ()s, the cocci script successfully generates a patch. -- Gustavo