devm_ioremap() in a sysfs show method
Martin Kaiser
lists at kaiser.cx
Mon Apr 24 05:53:21 EDT 2017
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
More information about the Kernelnewbies
mailing list