mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: iw3gtf@arcor.de
Cc: barebox@lists.infradead.org
Subject: Re: Re: [PATCH 2/2] commands: ubi: added the new command 'ubirename' to rename ubi volumes.
Date: Tue, 27 Sep 2016 08:23:40 +0200	[thread overview]
Message-ID: <20160927062340.u2tvhcgyio2l5ue7@pengutronix.de> (raw)
In-Reply-To: <405969938.1037814.1474625516057.JavaMail.ngmail@webmail12.arcor-online.net>

On Fri, Sep 23, 2016 at 12:11:56PM +0200, iw3gtf@arcor.de wrote:
> Hi,
> 
> 
> ----- Original Nachricht ----
> Von:     Sascha Hauer <s.hauer@pengutronix.de>
> An:      Giorgio Dal Molin <iw3gtf@arcor.de>
> Datum:   22.09.2016 10:04
> Betreff: Re: [PATCH 2/2] commands: ubi: added the new command 'ubirename' to
>  rename ubi volumes.
> 
> > On Wed, Sep 21, 2016 at 10:04:43AM +0200, Giorgio Dal Molin wrote:
> > > From: Giorgio Dal Molin <giorgio.dal.molin@mobotix.com>
> > > 
> > > The syntax was taken from the corresponding command of the 'mts-utils'
> > > userland package:
> > > 
> > > # ubirename UBIDEV OLD_NAME NEW_NAME [OLD_NAME NEW_NAME ...]
> > > 
> > > Signed-off-by: Giorgio Dal Molin <iw3gtf@arcor.de>
> > > ---
> > >  commands/ubi.c | 87
> > ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> > >  1 file changed, 87 insertions(+)
> > > 
> > > diff --git a/commands/ubi.c b/commands/ubi.c
> > > index 26b521f..3479340 100644
> > > --- a/commands/ubi.c
> > > +++ b/commands/ubi.c
> > > @@ -6,6 +6,8 @@
> > >  #include <errno.h>
> > >  #include <getopt.h>
> > >  #include <linux/mtd/mtd.h>
> > > +#include <linux/mtd/ubi.h>
> > > +#include <libgen.h>
> > >  #include <linux/kernel.h>
> > >  #include <linux/stat.h>
> > >  #include <linux/mtd/mtd-abi.h>
> > > @@ -306,3 +308,88 @@ BAREBOX_CMD_START(ubirmvol)
> > >  	BAREBOX_CMD_GROUP(CMD_GRP_PART)
> > >  	BAREBOX_CMD_HELP(cmd_ubirmvol_help)
> > >  BAREBOX_CMD_END
> > > +
> > > +
> > > +static int get_vol_id(const char *vol_name)
> > > +{
> > > +	struct ubi_volume_desc *desc;
> > > +	struct cdev *vol_cdev;
> > > +	struct ubi_volume_info vi;
> > > +
> > > +	vol_cdev = cdev_by_name(vol_name);
> > > +	if(!vol_cdev) {
> > > +		perror("cdev_by_name");
> > > +		return -1;
> > > +	}
> > > +	desc = ubi_open_volume_cdev(vol_cdev, UBI_READONLY);
> > > +	if(IS_ERR(desc)) {
> > > +		perror("ubi_open_volume_cdev");
> > > +		return -1;
> > > +	}
> > > +	ubi_get_volume_info(desc, &vi);
> > > +	ubi_close_volume(desc);
> > > +
> > > +	return vi.vol_id;
> > > +};
> > 
> > This get_vol_id() is not particularly nice. Also I do not like having
> > the rename operation inside the ioctl parser as this means we cannot
> > make the ubirename code optional for users that do not need renaming.
> > 
> > I just sent out a series which should help you in this regard. Can you
> > base your code ontop of this?
> 
> I've noticed a problem in the 3rd patch ([PATCH 3/4] mtd: ubi: commands: use function API to access ubi volumes)
> of your last UBI serie: in the resulting code in 'commands/ubi.c', function 'do_ubirmvol()':
> 
> ...
> 	desc = ubi_open_volume_nm(ubinum, argv[2], UBI_EXCLUSIVE);
> 	if (IS_ERR(desc)) {
> 		ret = PTR_ERR(desc);
> 		printf("failed to open volume %s: %s\n", argv[2], strerror(-ret));
> 		goto err1;
> 	}
> 
> 	ret = ubi_api_remove_volume(desc, 0);
> 	if (ret)
> 		printf("failed to remove volume %s: %s\n", argv[2], strerror(-ret));
> 
> err1:
> 	ubi_close_volume(desc);
> err:
> 	close(fd);
> 
> 	return ret ? 1 : 0;
> }
> 
> You have a wrong 'goto err1': in that case the 'desc' pointer is not a memory address, it
> represent a negative error code and you cannot use it in ubi_close_volume(desc) (it segfaults).

Fixed that. Thanks for noting.

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

      reply	other threads:[~2016-09-27  6:24 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-21  8:04 [PATCH 0/2] added support for renaming UBI volumes Giorgio Dal Molin
2016-09-21  8:04 ` [PATCH 1/2] mtd: UBI: add support (ioctl) for renaming ubi volumes Giorgio Dal Molin
2016-09-21  8:04 ` [PATCH 2/2] commands: ubi: added the new command 'ubirename' to rename " Giorgio Dal Molin
2016-09-22  8:04   ` Sascha Hauer
2016-09-23  9:07     ` [PATCH 0/2] mtd: ubi: implement the new command 'ubirename' Giorgio Dal Molin
2016-09-23  9:07     ` [PATCH 1/2] mtd: ubi: add API call to rename volumes Giorgio Dal Molin
2016-09-23  9:07     ` [PATCH 2/2] mtd: ubi: commands: added the new command 'ubirename' Giorgio Dal Molin
2016-09-26  6:19       ` Sascha Hauer
2016-09-26 10:52         ` [PATCH 0/2 (try 2)] mtd: ubi: implement " Giorgio Dal Molin
2016-09-27  6:21           ` Sascha Hauer
2016-09-26 10:52         ` [PATCH 1/2] mtd: ubi: add API call to rename volumes Giorgio Dal Molin
2016-09-26 10:52         ` [PATCH 2/2] mtd: ubi: commands: added the new command 'ubirename' Giorgio Dal Molin
2016-09-23 10:11   ` Aw: Re: [PATCH 2/2] commands: ubi: added the new command 'ubirename' to rename ubi volumes iw3gtf
2016-09-27  6:23     ` Sascha Hauer [this message]

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=20160927062340.u2tvhcgyio2l5ue7@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=iw3gtf@arcor.de \
    /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