Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp897831ybi; Wed, 3 Jul 2019 06:21:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqxY2lkyY7SilIHnb+SW+FJSgtcvWd8Q4IidZm2SU6X5LivavTddFXIR+1EUOZeW2zaHfMmJ X-Received: by 2002:a65:63cd:: with SMTP id n13mr36919663pgv.153.1562160086468; Wed, 03 Jul 2019 06:21:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562160086; cv=none; d=google.com; s=arc-20160816; b=wz4cmhV2m2HE6a3HzrVjIlF+JKCBKJgux2/Nd2U715Kt+/R10/jv+tKcVJG7BtvZS/ fRWgyCRPpwPu7/n9Xp1xq2ptDPIXmlQ7jVzn12MNSkFziWMQMAuix0ykBe7QwslAHWVh Xh92eAEDqdmqrtNeD4V+gJJaXnuCE41NIsimkJIpk4Nf2eX0vIqUPyJC+M09/3TNK6zN yAMBAB/qsTolroVE+fat6v0e7GIUTbDgqCZ0/gWuP2dtP7FkHlMLjeza58EaLDGY4oYv SipIBDxTrKGZEf+RleYwSj8kLLr2mqLmopmq2gw0GHFWja/lp1Gccd2AQA3rnN8EvNAZ i4rA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=lh03SiMTXDB9kYjUCArwWbtvnoP0VQ3+8H0ObHrYEmA=; b=EuLvxRKBuGxS5PrdPLub2XbRNvqGL5srFueUfOWBldAuHuadM3zjOUT7fkJNA9qMYa v7afEa2Tz/Wql+IuWqvozkeGmWHqBl9UqYSCi1ZBKCLYs0DVrktlj8QwTZNzLd7L+yC8 M+O9zBrE7mi2zjANoZsvRVitpxv30fCvlAfF4hK2fcMRhgnhvJMySFpOsnak7gacAnYB W+Es4Jbp9jvlbEB/riS2x75dYsF+GSmrfNyNpmO5SO//FYLfIB4FbuOMAXp8JQDq2ByD spSpOYO6CGQav7FC13ScqfaxTfOViRltrwSKPd274OfKLwDKYqB46aU3cr/W1Pn82XvD NbbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=Cc7c7iey; 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 d92si2299873pld.262.2019.07.03.06.21.10; Wed, 03 Jul 2019 06:21:26 -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=pass header.i=@c-s.fr header.s=mail header.b=Cc7c7iey; 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 S1727227AbfGCNT2 (ORCPT + 99 others); Wed, 3 Jul 2019 09:19:28 -0400 Received: from pegase1.c-s.fr ([93.17.236.30]:1735 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725847AbfGCNT2 (ORCPT ); Wed, 3 Jul 2019 09:19:28 -0400 Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 45f1sn4cdnz9v01x; Wed, 3 Jul 2019 15:19:25 +0200 (CEST) Authentication-Results: localhost; dkim=pass reason="1024-bit key; insecure key" header.d=c-s.fr header.i=@c-s.fr header.b=Cc7c7iey; dkim-adsp=pass; dkim-atps=neutral X-Virus-Scanned: Debian amavisd-new at c-s.fr Received: from pegase1.c-s.fr ([192.168.12.234]) by localhost (pegase1.c-s.fr [192.168.12.234]) (amavisd-new, port 10024) with ESMTP id zOalVqxx5uRw; Wed, 3 Jul 2019 15:19:25 +0200 (CEST) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase1.c-s.fr (Postfix) with ESMTP id 45f1sn3b62z9v01w; Wed, 3 Jul 2019 15:19:25 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1562159965; bh=lh03SiMTXDB9kYjUCArwWbtvnoP0VQ3+8H0ObHrYEmA=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=Cc7c7ieyDxvj43rPPEUjaRF+pbzbGG8S5qzI3a/7zaV43cnz3lPFtnnnH44KKNLpl 4nk1r9qVOgaIOPQHXOVNsNe19+rKZCeoujEscx0NqZTukGD6NlZRvk+Tb1S1uhDA+5 ohHyJfToeSWAaGEQjYorjyiAr2BM0m1f2FPZ9wrY= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id EC77C8B815; Wed, 3 Jul 2019 15:19:26 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id Ssm5YARw6vJA; Wed, 3 Jul 2019 15:19:26 +0200 (CEST) Received: from [192.168.4.90] (unknown [192.168.4.90]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 9DAF98B811; Wed, 3 Jul 2019 15:19:26 +0200 (CEST) Subject: Re: [PATCH 02/30] powerpc: Use kmemdup rather than duplicating its implementation To: Fuqian Huang Cc: linux-kernel@vger.kernel.org, Paul Mackerras , linuxppc-dev@lists.ozlabs.org References: <20190703131327.24762-1-huangfq.daxian@gmail.com> From: Christophe Leroy Message-ID: <80d073af-f7b5-6c9d-de51-110f14d15380@c-s.fr> Date: Wed, 3 Jul 2019 15:19:26 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 MIME-Version: 1.0 In-Reply-To: <20190703131327.24762-1-huangfq.daxian@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: fr Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Le 03/07/2019 à 15:13, Fuqian Huang a écrit : > kmemdup is introduced to duplicate a region of memory in a neat way. > Rather than kmalloc/kzalloc + memset, which the programmer needs to > write the size twice (sometimes lead to mistakes), kmemdup improves > readability, leads to smaller code and also reduce the chances of mistakes. > Suggestion to use kmemdup rather than using kmalloc/kzalloc + memset. s/memset/memcpy/ > > Add an allocation failure check. Shouldn't this be in another patch ? Christophe > > Signed-off-by: Fuqian Huang > --- > arch/powerpc/platforms/pseries/dlpar.c | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > > diff --git a/arch/powerpc/platforms/pseries/dlpar.c b/arch/powerpc/platforms/pseries/dlpar.c > index 437a74173db2..20fe7b79e09e 100644 > --- a/arch/powerpc/platforms/pseries/dlpar.c > +++ b/arch/powerpc/platforms/pseries/dlpar.c > @@ -383,9 +383,10 @@ void queue_hotplug_event(struct pseries_hp_errorlog *hp_errlog) > struct pseries_hp_work *work; > struct pseries_hp_errorlog *hp_errlog_copy; > > - hp_errlog_copy = kmalloc(sizeof(struct pseries_hp_errorlog), > + hp_errlog_copy = kmemdup(hp_errlog, sizeof(struct pseries_hp_errorlog), > GFP_KERNEL); > - memcpy(hp_errlog_copy, hp_errlog, sizeof(struct pseries_hp_errorlog)); > + if (!hp_errlog_copy) > + return; > > work = kmalloc(sizeof(struct pseries_hp_work), GFP_KERNEL); > if (work) { >