From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934247AbcIXP3f (ORCPT ); Sat, 24 Sep 2016 11:29:35 -0400 Received: from mout.web.de ([212.227.15.14]:62217 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933272AbcIXP3c (ORCPT ); Sat, 24 Sep 2016 11:29:32 -0400 Subject: Re: [PATCH 01/10] firewire-net: Use kmalloc_array() in fwnet_broadcast_start() To: Stefan Richter References: <566ABCD9.1060404@users.sourceforge.net> <20160924134110.35e63471@kant> Cc: linux1394-devel@lists.sourceforge.net, LKML , kernel-janitors@vger.kernel.org, Julia Lawall , Paolo Bonzini From: SF Markus Elfring Message-ID: <3b7dacb0-6387-5214-e112-19d51b053e19@users.sourceforge.net> Date: Sat, 24 Sep 2016 17:29:00 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.3.0 MIME-Version: 1.0 In-Reply-To: <20160924134110.35e63471@kant> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-Provags-ID: V03:K0:XzaiS/wZYpAkgvssWc21N0qbAaFDYe2RzIi7W9frs0T3b5M8W/T 1F/jxsIB8qIaGUmMmQBaYk3g7rhSwJk/AQXnfCZjRcfoipUq61pWZGnBLxzmR4wmEoCpWQT 7e/wlK4lnH9uA32dCz6StpQ+X3ofovw76rr7qgHpu8t7k7MalnWcpfDwO68pqGX/j4EWjN9 /bKhX/dmXIjLYaBe6gCFQ== X-UI-Out-Filterresults: notjunk:1;V01:K0:TsE2ARj7B8k=:1Yu6FLvogzf9cNIoKkovf6 kLME59/MQdU+5VyUUJjbCb7opf1o+SHCRBlONdXpEU3mvNMFe1hT/Ce8qUmEjFL3uvU7kZzxU 1wKSQ0uTHaRMjJnZm6TcTZyZ7gwbd4qyX1cdC9bKJi4AJFg3dHkm72gipFnYjqFpeEdYwlsu/ aR9jdeB1F+PexccG9NmEh2NQd9+l7553pDSXXsE36oNQue+shaNuneqTkOcHBccugQ87N0RrI Qg/6Tu2tslfLEj3O18McUn6xQ14nQJuLodtRLMu0vNl+JN5PcMrSyLeBtRqhdlnAe1pbTpIMp q7t+ob7fEgUZ1aiEZHZcWCt2AZDoqGBLSuAGyxcBsSVgh1Bp8dBctqIswykEg0YXwBgxBwp16 Zu3gjiGq4bJlD9QlWTIfXjt3m5p2NBfOSTNr6S6DV1I6mgfQLuqcaAaqHLRKGlqCwI3It8WxE z+ja1UOuMPtgMeAit0K06x8WyGEb2QZVxgOky4WGADnpmCfyNV1EQ4d2Wh4s6pjyMlJUPGLKD b6MAwdWyMRU1RZBDtNiQ6XcHd4GvqlgGkZMzP4XoJZOXj2b4eh2dOhaDMaEHGozF6CttwQWvp De+46udg0mMY2CM2mQTdLFni6j8yz4CLtxPWamkD0sBTFzeFyUKNqTcWB+YYLv76M6NumN256 w2+39cHnDyTJOhykGo05hxYICBSPsmgvj0xvL6Vb0CiTO1zO7oYkIf/DWsBG3kR9HTOaCW8vR Afn1csiJuKMWxkdXit1GEyPVLnN8KJVB3xV4FLtGkiYqa86gFtOjlMl5qwaAi6mEuuVArqd4m 8SCU14A Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org >> @@ -1103,8 +1103,7 @@ static int fwnet_broadcast_start(struct fwnet_device *dev) >> >> max_receive = 1U << (dev->card->max_receive + 1); >> num_packets = (FWNET_ISO_PAGE_COUNT * PAGE_SIZE) / max_receive; >> - >> - ptrptr = kmalloc(sizeof(void *) * num_packets, GFP_KERNEL); >> + ptrptr = kmalloc_array(num_packets, sizeof(*ptrptr), GFP_KERNEL); >> if (!ptrptr) { >> retval = -ENOMEM; >> goto failed; > > Coccinelle enabled you to determine that kmalloc_array /could/ be used here. A script for the semantic patch language pointed hundreds of source files out with such software update opportunities. > But whether it /should/ be used here is another question, and it is > not addressed in your changelog. I can expand the corresponding description when it will be desired. > (You state that there is an "issue" but do not explain.) Do you prefer an other wording for such an update candidate? > kmalloc_array is a kmalloc wrapper which adds an inline check for integer > overflow. So, can sizeof(void *) * num_packets ever overflow size_t? > > If yes, Is there a probability that the calculated number of packets will become too big for the preferred system limits anyhow? > do we want a runtime check here (which kmalloc_array provides), Did you notice the information from the commit "mm: faster kmalloc_array(), kcalloc()" (from 2016-07-26) already? https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/commit/?id=91c6a05f72a996bee5133e76374ab3ad7d3b9b72 > or do we want a compile-time check? I guess that some software developers and subsystem maintainers are looking for a bit more clarification around involved design dependencies. > If no, > then the remaining benefit of the patch is that it is more obvious > to the reader that dev->broadcast_rcv_buffer_ptrs is an array, How do you value such a kind of source code annotation? > but possibly at the cost of superfluous code. How do you think about to care for a bit more consistent use of Linux programming interfaces? > Is gcc's optimizer able to resolve kmalloc_array's check at compile time > as always false, such that the superfluous code is eliminated as dead code? Which versions of compiler implementations would you like to check further? > I believe I know answers to this but prefer to hear what you as the patch > author think about it. I presented another update suggestion also for this software module as a result from a general source code search pattern. The corresponding change acceptance varies and is evolving as usual. Regards, Markus