Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp3414255ybl; Mon, 19 Aug 2019 18:31:04 -0700 (PDT) X-Google-Smtp-Source: APXvYqy268TbjXt2PrtHWzFt2Odpweu7Po0u57C4Op5OWeoLQLlzdmZ2LMoscgSMrK7l3fu7mf/r X-Received: by 2002:a62:1715:: with SMTP id 21mr27493881pfx.134.1566264664072; Mon, 19 Aug 2019 18:31:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566264664; cv=none; d=google.com; s=arc-20160816; b=PDop91/noG6sPCM6BY1RLpZMXzUly84AV7SfSsTHgaUwXi/ignVjEEVuV/TqQWLyTq 9jwkP/7PILl3JJNi2N7LYmkHok7eyaTxhTDleys0xEyPXl8CQTPHRJMru0IA2ZKfl2kx Fg4oHcbnWvpfHOVYV3kNrE7FsVaBVfMTOwc+bEVbQBOBLe7iwydhNbm9YS7Sm7Ur04QW rplr4paYNxVCEaBrRfwWy05jQin0UAjmw2wfTqie+dkEV4PfKlP9Cce0SlD5FQ2sZTk/ C3djzSFZlP4Xn6/eu2ejUZo5LN/G5VbRhIb21eUmxFR83UN8F5oEcvduAajXz5tbpMMA jzEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=bpCrccGQA8l7BTcc8eWw96H6pS6MQIOOzUEqeqPrzKU=; b=C3uliDaJowerrmACNHRnU7V6VJPq98cQoyRZdh+AT03Kfgx0MX3/rBuabgHCs2y0SM sR2jsDRk6lAaQvWwxAkCSk/2VEnDakOqZSQW1baMwaPeQC2fI2gWs/F5NynPYw3TdyYg O75cdJBW/flXH5IKjGdgLFHEq45Q0DxvCWEZKWVeeikDVF8fV5514CI9cjuw9bOBwhpj TvyyvO1XQ2pdnRUX8yTZp7mfWA2M/7gZk3qEbwgXS/GPYWVBHOl0KgkUkhAjHX0rnKdQ JOFkXEqZSXqvQBekoOpxMVLTt+CH85dzuiztOVlOmA3gfWT6oopWnIy52KZp8QXeuSJc jUgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel-com.20150623.gappssmtp.com header.s=20150623 header.b="lZbsZt+/"; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f188si10247537pfb.22.2019.08.19.18.30.49; Mon, 19 Aug 2019 18:31:04 -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=@intel-com.20150623.gappssmtp.com header.s=20150623 header.b="lZbsZt+/"; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728903AbfHTB2m (ORCPT + 99 others); Mon, 19 Aug 2019 21:28:42 -0400 Received: from mail-ot1-f67.google.com ([209.85.210.67]:42579 "EHLO mail-ot1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728734AbfHTB2m (ORCPT ); Mon, 19 Aug 2019 21:28:42 -0400 Received: by mail-ot1-f67.google.com with SMTP id j7so3524188ota.9 for ; Mon, 19 Aug 2019 18:28:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=bpCrccGQA8l7BTcc8eWw96H6pS6MQIOOzUEqeqPrzKU=; b=lZbsZt+/6d5yJAVD8m/RWxrbst/pw6mXm9sXy042kGJEQR9cu7lYZjLiBf6dwe8kdd x073MY1NIze1gOonl8UPKw/Tk5EF1OpFoPQGBl5XHSPHM3FU1oVNtDcJqg89FstWApDZ fcibc6V2UzCg8TM7EzkiczR5EkpxjjjuQLLKPRPQJq02SSicgxK0jB80zPnLkyusZNYE Slg72DBH/UYm3UkD6+qsNs8SVJRkNhZMpJr+9jeb1ioXRRn/PjlKF0yV+Nm9dfMO3FUR eIYBUiC3kTdhj84CPutziyMUYtE+g4LnP3j8x3sgoJ+m+Ui16TzkRosrQJJTFUJX8F4e dqxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=bpCrccGQA8l7BTcc8eWw96H6pS6MQIOOzUEqeqPrzKU=; b=DbIbagSv5/bcSWhjFTVruIW7bI89c7raJMZGolSmhEiafzs3H4XUN5Ss7M5PEGw7AC NYlLij6w2Yb9fOdq1dvPCu991jEqzymT+LlvU9iX07uhFJVjaM9wb2YypeImgrqpvU4s Sln4oo6n/rXHRVJZIEXKNtHNN6khCb5c+SGwUHkwstlhxwaipkChZFIqW9ciDUKOqdkC JRlD8BfcNcdy6ZUvpSP2C+JJ45+5OX7vHCUq46sFIh1BGQpQoxebvH/uBs9654UgAqud jVbXKwnJvfVPcTgDlLIjOLyz3mIR5ZnAYXpkVs1XlEofYNxYKf+Vh175a9rtliLA09eg RJBw== X-Gm-Message-State: APjAAAUwuk7c7oeZjKG1L+f5aauZ3FngEEhqkEMBrB+YV4gYrdPvolfy qmv2SRjC92+pxSqQDL0iYWgPAa18f01TDHw2n5piMg== X-Received: by 2002:a05:6830:458:: with SMTP id d24mr19871635otc.126.1566264521208; Mon, 19 Aug 2019 18:28:41 -0700 (PDT) MIME-Version: 1.0 References: <20190818090557.17853-1-hch@lst.de> <20190818090557.17853-2-hch@lst.de> In-Reply-To: <20190818090557.17853-2-hch@lst.de> From: Dan Williams Date: Mon, 19 Aug 2019 18:28:30 -0700 Message-ID: Subject: Re: [PATCH 1/4] resource: add a not device managed request_free_mem_region variant To: Christoph Hellwig Cc: Jason Gunthorpe , Bharata B Rao , Andrew Morton , Linux MM , Linux Kernel Mailing List , linux-nvdimm , Ira Weiny Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Aug 18, 2019 at 2:10 AM Christoph Hellwig wrote: > > Factor out the guts of devm_request_free_mem_region so that we can > implement both a device managed and a manually release version as > tiny wrappers around it. > > Signed-off-by: Christoph Hellwig > Reviewed-by: Ira Weiny > --- > include/linux/ioport.h | 2 ++ > kernel/resource.c | 45 +++++++++++++++++++++++++++++------------- > 2 files changed, 33 insertions(+), 14 deletions(-) > > diff --git a/include/linux/ioport.h b/include/linux/ioport.h > index 5b6a7121c9f0..7bddddfc76d6 100644 > --- a/include/linux/ioport.h > +++ b/include/linux/ioport.h > @@ -297,6 +297,8 @@ static inline bool resource_overlaps(struct resource *r1, struct resource *r2) > > struct resource *devm_request_free_mem_region(struct device *dev, > struct resource *base, unsigned long size); > +struct resource *request_free_mem_region(struct resource *base, > + unsigned long size, const char *name); > > #endif /* __ASSEMBLY__ */ > #endif /* _LINUX_IOPORT_H */ > diff --git a/kernel/resource.c b/kernel/resource.c > index 7ea4306503c5..74877e9d90ca 100644 > --- a/kernel/resource.c > +++ b/kernel/resource.c > @@ -1644,19 +1644,8 @@ void resource_list_free(struct list_head *head) > EXPORT_SYMBOL(resource_list_free); > > #ifdef CONFIG_DEVICE_PRIVATE > -/** > - * devm_request_free_mem_region - find free region for device private memory > - * > - * @dev: device struct to bind the resource to > - * @size: size in bytes of the device memory to add > - * @base: resource tree to look in > - * > - * This function tries to find an empty range of physical address big enough to > - * contain the new resource, so that it can later be hotplugged as ZONE_DEVICE > - * memory, which in turn allocates struct pages. > - */ > -struct resource *devm_request_free_mem_region(struct device *dev, > - struct resource *base, unsigned long size) > +static struct resource *__request_free_mem_region(struct device *dev, > + struct resource *base, unsigned long size, const char *name) > { > resource_size_t end, addr; > struct resource *res; > @@ -1670,7 +1659,10 @@ struct resource *devm_request_free_mem_region(struct device *dev, > REGION_DISJOINT) > continue; > > - res = devm_request_mem_region(dev, addr, size, dev_name(dev)); > + if (dev) > + res = devm_request_mem_region(dev, addr, size, name); > + else > + res = request_mem_region(addr, size, name); > if (!res) > return ERR_PTR(-ENOMEM); > res->desc = IORES_DESC_DEVICE_PRIVATE_MEMORY; > @@ -1679,7 +1671,32 @@ struct resource *devm_request_free_mem_region(struct device *dev, > > return ERR_PTR(-ERANGE); > } > + > +/** > + * devm_request_free_mem_region - find free region for device private memory > + * > + * @dev: device struct to bind the resource to > + * @size: size in bytes of the device memory to add > + * @base: resource tree to look in > + * > + * This function tries to find an empty range of physical address big enough to > + * contain the new resource, so that it can later be hotplugged as ZONE_DEVICE > + * memory, which in turn allocates struct pages. > + */ > +struct resource *devm_request_free_mem_region(struct device *dev, > + struct resource *base, unsigned long size) > +{ Previously we would loudly crash if someone passed NULL to devm_request_free_mem_region(), but now it will silently work and the result will leak. Perhaps this wants a: if (!dev) return NULL; ...to head off those mistakes? No major heartburn if you keep it as is, you can add: Reviewed-by: Dan Williams