kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
From: lists@kaiser.cx (Martin Kaiser)
To: kernelnewbies@lists.kernelnewbies.org
Subject: devm_ioremap() in a sysfs show method
Date: Mon, 24 Apr 2017 11:53:21 +0200	[thread overview]
Message-ID: <20170424095321.GA30492@botnar.kaiser.cx> (raw)

Dear all,

I'm trying to create a simple sysfs node that prints the content of a
register. The code looks like this

static ssize_t
my_read_reg(struct device *pdev, struct device_attribute *attr, char *buf)
{
    u32 __iomem *reg;

    reg = devm_ioremap(pdev, 0x581018C4, 4);
    return scnprintf(buf, PAGE_SIZE, "0x%02x\n", ioread8(reg));
}

Is it ok to use devm_ioremap() on the device that I get here? If so, may
I assume that devm_ioremap() re-uses an existing mapping and it's ok to
call it for each sysfs access?

The physical address that I pass to devm_ioremap() is not page-aligned.
This seems to work on arm. Is there a recommended (i.e. more portable)
way of doing this? Should I map a larger area and use PAGE_ALIGN()?

Thanks for your feedback,

   Martin

             reply	other threads:[~2017-04-24  9:53 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-24  9:53 Martin Kaiser [this message]
2017-05-09 13:47 ` devm_ioremap() in a sysfs show method Martin Kaiser

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=20170424095321.GA30492@botnar.kaiser.cx \
    --to=lists@kaiser.cx \
    --cc=kernelnewbies@lists.kernelnewbies.org \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).