From: "Leizhen (ThunderTown)" <thunder.leizhen@huawei.com> To: Dan Williams <dan.j.williams@intel.com>, Vishal Verma <vishal.l.verma@intel.com>, Dave Jiang <dave.jiang@intel.com>, linux-nvdimm <linux-nvdimm@lists.01.org>, linux-kernel <linux-kernel@vger.kernel.org> Subject: Re: [PATCH 1/1] device-dax: avoid an unnecessary check in alloc_dev_dax_range() Date: Fri, 18 Dec 2020 14:09:15 +0800 [thread overview] Message-ID: <55970773-35ff-1afb-940b-8342b09aea9a@huawei.com> (raw) In-Reply-To: <20201120092251.2197-1-thunder.leizhen@huawei.com> On 2020/11/20 17:22, Zhen Lei wrote: > Swap the calling sequence of krealloc() and __request_region(), call the > latter first. In this way, the value of dev_dax->nr_range does not need to > be considered when __request_region() failed. > > Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com> > --- > drivers/dax/bus.c | 29 ++++++++++++----------------- > 1 file changed, 12 insertions(+), 17 deletions(-) > > diff --git a/drivers/dax/bus.c b/drivers/dax/bus.c > index 27513d311242..1efae11d947a 100644 > --- a/drivers/dax/bus.c > +++ b/drivers/dax/bus.c > @@ -763,23 +763,15 @@ static int alloc_dev_dax_range(struct dev_dax *dev_dax, u64 start, > return 0; > } > > - ranges = krealloc(dev_dax->ranges, sizeof(*ranges) > - * (dev_dax->nr_range + 1), GFP_KERNEL); > - if (!ranges) > - return -ENOMEM; > - > alloc = __request_region(res, start, size, dev_name(dev), 0); > - if (!alloc) { > - /* > - * If this was an empty set of ranges nothing else > - * will release @ranges, so do it now. > - */ > - if (!dev_dax->nr_range) { > - kfree(ranges); > - ranges = NULL; > - } > - dev_dax->ranges = ranges; > + if (!alloc) > return -ENOMEM; > + > + ranges = krealloc(dev_dax->ranges, sizeof(*ranges) > + * (dev_dax->nr_range + 1), GFP_KERNEL); > + if (!ranges) { > + rc = -ENOMEM; > + goto err; Hi, Dan Williams: In fact, after adding the new helper dev_dax_trim_range(), we can directly call __release_region() and return error code at here. Replace goto. > } > > for (i = 0; i < dev_dax->nr_range; i++) > @@ -808,11 +800,14 @@ static int alloc_dev_dax_range(struct dev_dax *dev_dax, u64 start, > dev_dbg(dev, "delete range[%d]: %pa:%pa\n", dev_dax->nr_range - 1, > &alloc->start, &alloc->end); > dev_dax->nr_range--; > - __release_region(res, alloc->start, resource_size(alloc)); > - return rc; > + goto err; > } > > return 0; > + > +err: > + __release_region(res, alloc->start, resource_size(alloc)); > + return rc; > } > > static int adjust_dev_dax_range(struct dev_dax *dev_dax, struct resource *res, resource_size_t size) > _______________________________________________ Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org To unsubscribe send an email to linux-nvdimm-leave@lists.01.org
WARNING: multiple messages have this Message-ID (diff)
From: "Leizhen (ThunderTown)" <thunder.leizhen@huawei.com> To: Dan Williams <dan.j.williams@intel.com>, Vishal Verma <vishal.l.verma@intel.com>, Dave Jiang <dave.jiang@intel.com>, linux-nvdimm <linux-nvdimm@lists.01.org>, linux-kernel <linux-kernel@vger.kernel.org> Subject: Re: [PATCH 1/1] device-dax: avoid an unnecessary check in alloc_dev_dax_range() Date: Fri, 18 Dec 2020 14:09:15 +0800 [thread overview] Message-ID: <55970773-35ff-1afb-940b-8342b09aea9a@huawei.com> (raw) In-Reply-To: <20201120092251.2197-1-thunder.leizhen@huawei.com> On 2020/11/20 17:22, Zhen Lei wrote: > Swap the calling sequence of krealloc() and __request_region(), call the > latter first. In this way, the value of dev_dax->nr_range does not need to > be considered when __request_region() failed. > > Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com> > --- > drivers/dax/bus.c | 29 ++++++++++++----------------- > 1 file changed, 12 insertions(+), 17 deletions(-) > > diff --git a/drivers/dax/bus.c b/drivers/dax/bus.c > index 27513d311242..1efae11d947a 100644 > --- a/drivers/dax/bus.c > +++ b/drivers/dax/bus.c > @@ -763,23 +763,15 @@ static int alloc_dev_dax_range(struct dev_dax *dev_dax, u64 start, > return 0; > } > > - ranges = krealloc(dev_dax->ranges, sizeof(*ranges) > - * (dev_dax->nr_range + 1), GFP_KERNEL); > - if (!ranges) > - return -ENOMEM; > - > alloc = __request_region(res, start, size, dev_name(dev), 0); > - if (!alloc) { > - /* > - * If this was an empty set of ranges nothing else > - * will release @ranges, so do it now. > - */ > - if (!dev_dax->nr_range) { > - kfree(ranges); > - ranges = NULL; > - } > - dev_dax->ranges = ranges; > + if (!alloc) > return -ENOMEM; > + > + ranges = krealloc(dev_dax->ranges, sizeof(*ranges) > + * (dev_dax->nr_range + 1), GFP_KERNEL); > + if (!ranges) { > + rc = -ENOMEM; > + goto err; Hi, Dan Williams: In fact, after adding the new helper dev_dax_trim_range(), we can directly call __release_region() and return error code at here. Replace goto. > } > > for (i = 0; i < dev_dax->nr_range; i++) > @@ -808,11 +800,14 @@ static int alloc_dev_dax_range(struct dev_dax *dev_dax, u64 start, > dev_dbg(dev, "delete range[%d]: %pa:%pa\n", dev_dax->nr_range - 1, > &alloc->start, &alloc->end); > dev_dax->nr_range--; > - __release_region(res, alloc->start, resource_size(alloc)); > - return rc; > + goto err; > } > > return 0; > + > +err: > + __release_region(res, alloc->start, resource_size(alloc)); > + return rc; > } > > static int adjust_dev_dax_range(struct dev_dax *dev_dax, struct resource *res, resource_size_t size) >
next prev parent reply other threads:[~2020-12-18 6:09 UTC|newest] Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-11-20 9:22 [PATCH 1/1] device-dax: avoid an unnecessary check in alloc_dev_dax_range() Zhen Lei 2020-11-20 9:22 ` Zhen Lei 2020-12-18 3:10 ` Dan Williams 2020-12-18 3:10 ` Dan Williams 2020-12-18 6:02 ` Leizhen (ThunderTown) 2020-12-18 6:02 ` Leizhen (ThunderTown) 2020-12-18 6:09 ` Leizhen (ThunderTown) [this message] 2020-12-18 6:09 ` Leizhen (ThunderTown)
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=55970773-35ff-1afb-940b-8342b09aea9a@huawei.com \ --to=thunder.leizhen@huawei.com \ --cc=dan.j.williams@intel.com \ --cc=dave.jiang@intel.com \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-nvdimm@lists.01.org \ --cc=vishal.l.verma@intel.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.