From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E2028C432C0 for ; Thu, 21 Nov 2019 21:37:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BDA6F2068E for ; Thu, 21 Nov 2019 21:37:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726962AbfKUVhh (ORCPT ); Thu, 21 Nov 2019 16:37:37 -0500 Received: from smtprelay0027.hostedemail.com ([216.40.44.27]:39566 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726540AbfKUVhh (ORCPT ); Thu, 21 Nov 2019 16:37:37 -0500 Received: from filter.hostedemail.com (clb03-v110.bra.tucows.net [216.40.38.60]) by smtprelay04.hostedemail.com (Postfix) with ESMTP id 215181806ECD0; Thu, 21 Nov 2019 21:37:36 +0000 (UTC) X-Session-Marker: 6A6F6540706572636865732E636F6D X-HE-Tag: toes80_25057537f620a X-Filterd-Recvd-Size: 2697 Received: from XPS-9350.home (unknown [47.151.135.224]) (Authenticated sender: joe@perches.com) by omf16.hostedemail.com (Postfix) with ESMTPA; Thu, 21 Nov 2019 21:37:34 +0000 (UTC) Message-ID: <38d4586f3aeb21bb08028525db89868acb34e9fd.camel@perches.com> Subject: Re: [PATCH v4 8/8] iommu/vt-d: Misc macro clean up for SVM From: Joe Perches To: Jacob Pan , iommu@lists.linux-foundation.org, LKML , Joerg Roedel , Lu Baolu , David Woodhouse Cc: "Tian, Kevin" , Raj Ashok , Yi Liu , Eric Auger , "Mehta, Sohil" Date: Thu, 21 Nov 2019 13:37:10 -0800 In-Reply-To: <1574371588-65634-9-git-send-email-jacob.jun.pan@linux.intel.com> References: <1574371588-65634-1-git-send-email-jacob.jun.pan@linux.intel.com> <1574371588-65634-9-git-send-email-jacob.jun.pan@linux.intel.com> Content-Type: text/plain; charset="ISO-8859-1" User-Agent: Evolution 3.34.1-2 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 2019-11-21 at 13:26 -0800, Jacob Pan wrote: > Use combined macros for_each_svm_dev() to simplify SVM device iteration > and error checking. [] > diff --git a/drivers/iommu/intel-svm.c b/drivers/iommu/intel-svm.c [] > +#define for_each_svm_dev(sdev, svm, d) \ > + list_for_each_entry((sdev), &(svm)->devs, list) \ > + if ((d) != (sdev)->dev) {} else > + > int intel_svm_bind_mm(struct device *dev, int *pasid, int flags, struct svm_dev_ops *ops) > { > struct intel_iommu *iommu = intel_svm_device_to_iommu(dev); > @@ -274,15 +278,13 @@ int intel_svm_bind_mm(struct device *dev, int *pasid, int flags, struct svm_dev_ > goto out; > } > > - list_for_each_entry(sdev, &svm->devs, list) { > - if (dev == sdev->dev) { > - if (sdev->ops != ops) { > - ret = -EBUSY; > - goto out; > - } > - sdev->users++; > - goto success; > + for_each_svm_dev(sdev, svm, dev) { > + if (sdev->ops != ops) { > + ret = -EBUSY; > + goto out; > } > + sdev->users++; > + goto success; > } I think this does not read better as this is now a for_each loop that exits the loop on the first match. > > break; > @@ -427,43 +429,36 @@ int intel_svm_unbind_mm(struct device *dev, int pasid) > goto out; > } > > - if (!svm) > - goto out; > - > - list_for_each_entry(sdev, &svm->devs, list) { [] > + for_each_svm_dev(sdev, svm, dev) { I think this should not remove the !svm test above.