LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Stephen Boyd <swboyd@chromium.org>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-kernel@vger.kernel.org,
	Wei-Ning Huang <wnhuang@chromium.org>,
	Julius Werner <jwerner@chromium.org>,
	Brian Norris <briannorris@chromium.org>,
	Samuel Holland <samuel@sholland.org>,
	Guenter Roeck <groeck@chromium.org>
Subject: [PATCH v2 2/5] firmware: google: memconsole: Use devm_memremap()
Date: Fri, 10 May 2019 14:24:53 -0700	[thread overview]
Message-ID: <155752349303.14659.3560946140992031740@swboyd.mtv.corp.google.com> (raw)
In-Reply-To: <20190510180151.115254-3-swboyd@chromium.org>

Use the devm version of memremap so that we can delete the unmapping
code in driver remove, but more importantly so that we can unmap this
memory region if memconsole_sysfs_init() errors out for some reason.

Cc: Wei-Ning Huang <wnhuang@chromium.org>
Cc: Julius Werner <jwerner@chromium.org>
Cc: Brian Norris <briannorris@chromium.org>
Cc: Samuel Holland <samuel@sholland.org>
Cc: Guenter Roeck <groeck@chromium.org>
Signed-off-by: Stephen Boyd <swboyd@chromium.org>
---

Quoting Stephen Boyd (2019-05-10 11:01:48)
> diff --git a/drivers/firmware/google/memconsole-coreboot.c b/drivers/firmware/google/memconsole-coreboot.c
> index 86331807f1d5..0b29b27b86f5 100644
> --- a/drivers/firmware/google/memconsole-coreboot.c
> +++ b/drivers/firmware/google/memconsole-coreboot.c
> @@ -85,7 +85,7 @@ static int memconsole_probe(struct coreboot_device *dev)
>  
>         /* Read size only once to prevent overrun attack through /dev/mem. */
>         cbmem_console_size = tmp_cbmc->size_dont_access_after_boot;
> -       cbmem_console = memremap(dev->cbmem_ref.cbmem_addr,
> +       cbmem_console = devm_memremap(&dev->dev, dev->cbmem_ref.cbmem_addr,

Whoops, this returns an error pointer now. Here's an updated patch.

 drivers/firmware/google/memconsole-coreboot.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/firmware/google/memconsole-coreboot.c b/drivers/firmware/google/memconsole-coreboot.c
index 86331807f1d5..cc3797f1ba85 100644
--- a/drivers/firmware/google/memconsole-coreboot.c
+++ b/drivers/firmware/google/memconsole-coreboot.c
@@ -85,13 +85,13 @@ static int memconsole_probe(struct coreboot_device *dev)
 
 	/* Read size only once to prevent overrun attack through /dev/mem. */
 	cbmem_console_size = tmp_cbmc->size_dont_access_after_boot;
-	cbmem_console = memremap(dev->cbmem_ref.cbmem_addr,
+	cbmem_console = devm_memremap(&dev->dev, dev->cbmem_ref.cbmem_addr,
 				 cbmem_console_size + sizeof(*cbmem_console),
 				 MEMREMAP_WB);
 	memunmap(tmp_cbmc);
 
-	if (!cbmem_console)
-		return -ENOMEM;
+	if (IS_ERR(cbmem_console))
+		return PTR_ERR(cbmem_console);
 
 	memconsole_setup(memconsole_coreboot_read);
 
@@ -102,9 +102,6 @@ static int memconsole_remove(struct coreboot_device *dev)
 {
 	memconsole_exit();
 
-	if (cbmem_console)
-		memunmap(cbmem_console);
-
 	return 0;
 }
 

base-commit: e93c9c99a629c61837d5a7fc2120cd2b6c70dbdd
prerequisite-patch-id: b7c2a1e21fb108364f0e8cfaf1970cbc7903c750
-- 
Sent by a computer through tubes

  reply	other threads:[~2019-05-10 21:24 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-10 18:01 [PATCH 0/5] Misc Google coreboot driver fixes/cleanups Stephen Boyd
2019-05-10 18:01 ` [PATCH 1/5] firmware: google: Add a module_coreboot_driver() macro and use it Stephen Boyd
2019-05-13 17:33   ` Brian Norris
2019-05-10 18:01 ` [PATCH 2/5] firmware: google: memconsole: Use devm_memremap() Stephen Boyd
2019-05-10 21:24   ` Stephen Boyd [this message]
2019-05-10 18:01 ` [PATCH 3/5] firmware: google: memconsole: Drop __iomem on memremap memory Stephen Boyd
2019-05-10 18:01 ` [PATCH 4/5] firmware: google: memconsole: Drop global func pointer Stephen Boyd
2019-05-10 18:01 ` [PATCH 5/5] firmware: google: coreboot: Drop unnecessary headers Stephen Boyd
2019-05-10 18:11 ` [PATCH 0/5] Misc Google coreboot driver fixes/cleanups Julius Werner
2019-05-12 17:43 ` Samuel Holland

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=155752349303.14659.3560946140992031740@swboyd.mtv.corp.google.com \
    --to=swboyd@chromium.org \
    --cc=briannorris@chromium.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=groeck@chromium.org \
    --cc=jwerner@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=samuel@sholland.org \
    --cc=wnhuang@chromium.org \
    --subject='Re: [PATCH v2 2/5] firmware: google: memconsole: Use devm_memremap()' \
    /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: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).