From mboxrd@z Thu Jan 1 00:00:00 1970 From: walter harms Date: Mon, 29 Aug 2016 11:57:41 +0000 Subject: Re: [PATCH 1/2] sparc: Use kmalloc_array() in three functions Message-Id: <57C42335.5000106@bfs.de> List-Id: References: <0ca0235c-ddb9-0534-3bde-b4aaa48da92e@users.sourceforge.net> <4475e65d-415d-9cde-1fe1-c17e120849c4@redhat.com> In-Reply-To: <4475e65d-415d-9cde-1fe1-c17e120849c4@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: Paolo Bonzini Cc: SF Markus Elfring , sparclinux@vger.kernel.org, "David S. Miller" , LKML , kernel-janitors@vger.kernel.org, Julia Lawall Am 29.08.2016 11:47, schrieb Paolo Bonzini: > > > On 25/08/2016 10:22, SF Markus Elfring wrote: >> --- a/arch/sparc/kernel/led.c >> +++ b/arch/sparc/kernel/led.c >> @@ -69,7 +69,7 @@ static ssize_t led_proc_write(struct file *file, const char __user *buffer, >> if (count > LED_MAX_LENGTH) >> count = LED_MAX_LENGTH; >> >> - buf = kmalloc(sizeof(char) * (count + 1), GFP_KERNEL); >> + buf = kmalloc_array(count + 1, sizeof(*buf), GFP_KERNEL); >> if (!buf) >> return -ENOMEM; >> > > Here it's probably best to just remove sizeof(char) completely, as it's > 1 by definition. > > Paolo I would not do so, if you ever change buf to something else it would break, having a sizeof(*buf) here is harmless and a known pattern. re, wh From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757255AbcH2L5r (ORCPT ); Mon, 29 Aug 2016 07:57:47 -0400 Received: from mx01-fr.bfs.de ([193.174.231.67]:62891 "EHLO mx01-fr.bfs.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750909AbcH2L5p (ORCPT ); Mon, 29 Aug 2016 07:57:45 -0400 Message-ID: <57C42335.5000106@bfs.de> Date: Mon, 29 Aug 2016 13:57:41 +0200 From: walter harms Reply-To: wharms@bfs.de User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; de; rv:1.9.1.16) Gecko/20101125 SUSE/3.0.11 Thunderbird/3.0.11 MIME-Version: 1.0 To: Paolo Bonzini CC: SF Markus Elfring , sparclinux@vger.kernel.org, "David S. Miller" , LKML , kernel-janitors@vger.kernel.org, Julia Lawall Subject: Re: [PATCH 1/2] sparc: Use kmalloc_array() in three functions References: <0ca0235c-ddb9-0534-3bde-b4aaa48da92e@users.sourceforge.net> <4475e65d-415d-9cde-1fe1-c17e120849c4@redhat.com> In-Reply-To: <4475e65d-415d-9cde-1fe1-c17e120849c4@redhat.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Am 29.08.2016 11:47, schrieb Paolo Bonzini: > > > On 25/08/2016 10:22, SF Markus Elfring wrote: >> --- a/arch/sparc/kernel/led.c >> +++ b/arch/sparc/kernel/led.c >> @@ -69,7 +69,7 @@ static ssize_t led_proc_write(struct file *file, const char __user *buffer, >> if (count > LED_MAX_LENGTH) >> count = LED_MAX_LENGTH; >> >> - buf = kmalloc(sizeof(char) * (count + 1), GFP_KERNEL); >> + buf = kmalloc_array(count + 1, sizeof(*buf), GFP_KERNEL); >> if (!buf) >> return -ENOMEM; >> > > Here it's probably best to just remove sizeof(char) completely, as it's > 1 by definition. > > Paolo I would not do so, if you ever change buf to something else it would break, having a sizeof(*buf) here is harmless and a known pattern. re, wh