From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753216AbdBCLen (ORCPT ); Fri, 3 Feb 2017 06:34:43 -0500 Received: from foss.arm.com ([217.140.101.70]:47818 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752296AbdBCLem (ORCPT ); Fri, 3 Feb 2017 06:34:42 -0500 Subject: Re: [PATCH 1/1] iommu: to avoid an unnecessary assignment To: Zhen Lei , Joerg Roedel , iommu , linux-kernel References: <1486114502-10984-1-git-send-email-thunder.leizhen@huawei.com> Cc: Xinwei Hu , Zefan Li , Hanjun Guo , Tianhong Ding From: Robin Murphy Message-ID: <12dad1b8-1a5b-889b-c272-dbf8eda3b00a@arm.com> Date: Fri, 3 Feb 2017 11:34:38 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 MIME-Version: 1.0 In-Reply-To: <1486114502-10984-1-git-send-email-thunder.leizhen@huawei.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 03/02/17 09:35, Zhen Lei wrote: > Move the assignment statement into if branch above, where it only > needs to be. > > Signed-off-by: Zhen Lei > --- > drivers/iommu/iommu.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c > index dbe7f65..b231400 100644 > --- a/drivers/iommu/iommu.c > +++ b/drivers/iommu/iommu.c > @@ -1714,13 +1714,14 @@ int iommu_fwspec_add_ids(struct device *dev, u32 *ids, int num_ids) > fwspec = krealloc(dev->iommu_fwspec, size, GFP_KERNEL); > if (!fwspec) > return -ENOMEM; > + > + dev->iommu_fwspec = fwspec; > } > > for (i = 0; i < num_ids; i++) > fwspec->ids[fwspec->num_ids + i] = ids[i]; > > fwspec->num_ids += num_ids; > - dev->iommu_fwspec = fwspec; Strictly, it was done here because I like following transactional idioms, i.e. at any point dev->fwspec is either the old one or the fully-initialised new one. However, since the state of the new one immediately after realloc isn't uninitialised, but still directly equivalent to the old one, I don't see an issue with moving the assignemnt there, plus it does avoid a redundant reassignment the first time through. Reviewed-by: Robin Murphy > return 0; > } > EXPORT_SYMBOL_GPL(iommu_fwspec_add_ids); > -- > 2.5.0 > > > _______________________________________________ > iommu mailing list > iommu@lists.linux-foundation.org > https://lists.linuxfoundation.org/mailman/listinfo/iommu >