From: Brian Norris <computersforpeace@gmail.com>
To: Daniel Ehrenberg <dehrenberg@google.com>
Cc: Richard Weinberger <richard@nod.at>,
Gwendal Grignou <gwendal@chromium.org>,
"linux-mtd@lists.infradead.org" <linux-mtd@lists.infradead.org>,
Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>
Subject: Re: [PATCH v3 2/3] mtd: part: Add sysfs variable for offset of partition
Date: Mon, 30 Mar 2015 20:31:30 -0700 [thread overview]
Message-ID: <20150331033130.GW32500@ld-irv-0074> (raw)
In-Reply-To: <CAAK6Zt1L54X4_JWCXzMSAz7nP-5bEkVTz4JLQLtROj6frzwgKQ@mail.gmail.com>
On Mon, Mar 30, 2015 at 01:32:21PM -0700, Daniel Ehrenberg wrote:
> On Fri, Mar 27, 2015 at 5:53 PM, Brian Norris
> <computersforpeace@gmail.com> wrote:
> > On Fri, Mar 27, 2015 at 12:24:16PM -0700, Dan Ehrenberg wrote:
> >> This patch makes a sysfs variable called 'offset' on each partition
> >> which contains the offset in bytes from the beginning of the master
> >> device that the partition starts.
> >>
> >> Signed-off-by: Dan Ehrenberg <dehrenberg@chromium.org>
> >> ---
> >> drivers/mtd/mtdpart.c | 29 +++++++++++++++++++++++++++++
> >> 1 file changed, 29 insertions(+)
> >>
> >> diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c
> >> index a19ec5a..b8ed202 100644
> >> --- a/drivers/mtd/mtdpart.c
> >> +++ b/drivers/mtd/mtdpart.c
> >> @@ -554,6 +554,30 @@ out_register:
> >> return slave;
> >> }
> >>
> >> +static ssize_t mtd_partition_offset_show(struct device *dev,
> >> + struct device_attribute *attr, char *buf)
> >> +{
> >> + struct mtd_info *mtd = dev_get_drvdata(dev);
> >> + struct mtd_part *part = PART(mtd);
> >> + return snprintf(buf, PAGE_SIZE, "%lld\n", part->offset);
> >> +}
> >> +
> >> +static DEVICE_ATTR(offset, S_IRUGO, mtd_partition_offset_show, NULL);
> >
> > You'll want #include <linux/device.h>, just to be explicit.
> >
> > And if you're adding to the sysfs ABI, please update
> > Documentation/ABI/testing/sysfs-class-mtd
> >
> >> +
> >> +const static struct attribute *mtd_partition_attrs[] = {
> >
> > gcc complains:
> >
> > drivers/mtd/mtdpart.c:568:1: warning: 'static' is not at beginning of declaration [-Wold-style-declaration]
> >
> >> + &dev_attr_offset.attr,
> >> + NULL
> >> +};
> >> +
> >> +int mtd_add_partition_attrs(struct mtd_part *new)
> >
> > gcc and sprase complain:
> >
> > drivers/mtd/mtdpart.c:573:5: warning: no previous prototype for 'mtd_add_partition_attrs' [-Wmissing-prototypes]
> > drivers/mtd/mtdpart.c:573:5: warning: symbol 'mtd_add_partition_attrs' was not declared. Should it be static? [sparse]
>
> Thanks, not sure why these warnings haven't been showing up for me
> (while other warnings do, e.g., if I make an unused variable). I'll
> fix this and the docs in a new patch.
sparse is not run by default, and some of the gcc warnings might only be
available on newer gcc's and/or when building with extra warnings
enabled.
To build with extra warnings, you can use 'make W=1' or 'make W=2'. To
build with sparse checking you can use 'make C=1' or 'make C=2'. See
Makefile for details.
> >> +{
> >> + int ret = sysfs_create_files(&new->mtd.dev.kobj, mtd_partition_attrs);
> >> + if (ret)
> >> + printk(KERN_WARNING
> >> + "mtd: failed to create partition attrs, err=%d\n", ret);
> >> + return ret;
> >> +}
> >> +
> >> int mtd_add_partition(struct mtd_info *master, const char *name,
> >> long long offset, long long length)
> >> {
> >> @@ -603,6 +627,8 @@ int mtd_add_partition(struct mtd_info *master, const char *name,
> >>
> >> add_mtd_device(&new->mtd);
> >>
> >> + mtd_add_partition_attrs(new);
> >
> > Hmm, so you're adding the partition attribute only to dynamically
> > created partitions? I think we'll want it for all partitions. I know
> > the naming isn't completely straightforward, but some partitions are
> > added through add_mtd_device(), without calling mtd_add_partition().
>
> It's also called in add_mtd_partitions, as you can see just below. I
> tested this with static partitions and the attribute was visible.
Sorry, must have overlooked this.
> >
> >> +
> >> return ret;
> >> err_inv:
> >> mutex_unlock(&mtd_partitions_mutex);
> >> @@ -620,6 +646,8 @@ int mtd_del_partition(struct mtd_info *master, int partno)
> >> list_for_each_entry_safe(slave, next, &mtd_partitions, list)
> >> if ((slave->master == master) &&
> >> (slave->mtd.index == partno)) {
> >> + sysfs_remove_files(&slave->mtd.dev.kobj,
> >> + mtd_partition_attrs);
> >> ret = del_mtd_device(&slave->mtd);
> >> if (ret < 0)
> >> break;
> >> @@ -663,6 +691,7 @@ int add_mtd_partitions(struct mtd_info *master,
> >> mutex_unlock(&mtd_partitions_mutex);
> >>
> >> add_mtd_device(&slave->mtd);
> >> + mtd_add_partition_attrs(slave);
> >>
> >> cur_offset = slave->offset + slave->mtd.size;
Brian
next prev parent reply other threads:[~2015-03-31 3:31 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-27 19:24 [PATCH v3 0/3] Improve MTD dynamic partitioning support Dan Ehrenberg
2015-03-27 19:24 ` [PATCH v3 1/3] mtd: part: Create the master device node when partitioned Dan Ehrenberg
2015-03-27 19:24 ` [PATCH v3 2/3] mtd: part: Add sysfs variable for offset of partition Dan Ehrenberg
2015-03-28 0:53 ` Brian Norris
2015-03-30 20:32 ` Daniel Ehrenberg
2015-03-31 3:31 ` Brian Norris [this message]
2015-03-27 19:24 ` [PATCH v3 3/3] mtd: part: Remove partition overlap checks Dan Ehrenberg
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=20150331033130.GW32500@ld-irv-0074 \
--to=computersforpeace@gmail.com \
--cc=dehrenberg@google.com \
--cc=ezequiel@vanguardiasur.com.ar \
--cc=gwendal@chromium.org \
--cc=linux-mtd@lists.infradead.org \
--cc=richard@nod.at \
/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