From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: Christoph Hellwig <hch@lst.de>
Cc: sandeen@sandeen.net, linux-xfs@vger.kernel.org
Subject: Re: [PATCH 4/8] db: cleanup attr_set_f and attr_remove_f
Date: Sat, 9 May 2020 10:08:00 -0700 [thread overview]
Message-ID: <20200509170800.GR6714@magnolia> (raw)
In-Reply-To: <20200509170125.952508-5-hch@lst.de>
On Sat, May 09, 2020 at 07:01:21PM +0200, Christoph Hellwig wrote:
> Don't use local variables for information that is set in the da_args
> structure.
>
> Signed-off-by: Christoph Hellwig <hch@lst.de>
Seems like a good cleanup,
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
--D
> ---
> db/attrset.c | 67 ++++++++++++++++++++++------------------------------
> 1 file changed, 28 insertions(+), 39 deletions(-)
>
> diff --git a/db/attrset.c b/db/attrset.c
> index 1ff2eb85..0a464983 100644
> --- a/db/attrset.c
> +++ b/db/attrset.c
> @@ -67,10 +67,9 @@ attr_set_f(
> int argc,
> char **argv)
> {
> - struct xfs_inode *ip = NULL;
> - struct xfs_da_args args = { NULL };
> - char *name, *value, *sp;
> - int c, valuelen = 0;
> + struct xfs_da_args args = { };
> + char *sp;
> + int c;
>
> if (cur_typ == NULL) {
> dbprintf(_("no current type\n"));
> @@ -111,8 +110,9 @@ attr_set_f(
>
> /* value length */
> case 'v':
> - valuelen = (int)strtol(optarg, &sp, 0);
> - if (*sp != '\0' || valuelen < 0 || valuelen > 64*1024) {
> + args.valuelen = strtol(optarg, &sp, 0);
> + if (*sp != '\0' ||
> + args.valuelen < 0 || args.valuelen > 64 * 1024) {
> dbprintf(_("bad attr_set valuelen %s\n"), optarg);
> return 0;
> }
> @@ -129,35 +129,29 @@ attr_set_f(
> return 0;
> }
>
> - name = argv[optind];
> + args.name = (const unsigned char *)argv[optind];
> + args.namelen = strlen(argv[optind]);
>
> - if (valuelen) {
> - value = (char *)memalign(getpagesize(), valuelen);
> - if (!value) {
> - dbprintf(_("cannot allocate buffer (%d)\n"), valuelen);
> + if (args.valuelen) {
> + args.value = memalign(getpagesize(), args.valuelen);
> + if (!args.value) {
> + dbprintf(_("cannot allocate buffer (%d)\n"),
> + args.valuelen);
> goto out;
> }
> - memset(value, 'v', valuelen);
> - } else {
> - value = NULL;
> + memset(args.value, 'v', args.valuelen);
> }
>
> - if (libxfs_iget(mp, NULL, iocur_top->ino, 0, &ip,
> + if (libxfs_iget(mp, NULL, iocur_top->ino, 0, &args.dp,
> &xfs_default_ifork_ops)) {
> dbprintf(_("failed to iget inode %llu\n"),
> (unsigned long long)iocur_top->ino);
> goto out;
> }
>
> - args.dp = ip;
> - args.name = (unsigned char *)name;
> - args.namelen = strlen(name);
> - args.value = value;
> - args.valuelen = valuelen;
> -
> if (libxfs_attr_set(&args)) {
> dbprintf(_("failed to set attr %s on inode %llu\n"),
> - name, (unsigned long long)iocur_top->ino);
> + args.name, (unsigned long long)iocur_top->ino);
> goto out;
> }
>
> @@ -166,10 +160,10 @@ attr_set_f(
>
> out:
> mp->m_flags &= ~LIBXFS_MOUNT_COMPAT_ATTR;
> - if (ip)
> - libxfs_irele(ip);
> - if (value)
> - free(value);
> + if (args.dp)
> + libxfs_irele(args.dp);
> + if (args.value)
> + free(args.value);
> return 0;
> }
>
> @@ -178,9 +172,7 @@ attr_remove_f(
> int argc,
> char **argv)
> {
> - struct xfs_inode *ip = NULL;
> - struct xfs_da_args args = { NULL };
> - char *name;
> + struct xfs_da_args args = { };
> int c;
>
> if (cur_typ == NULL) {
> @@ -223,23 +215,20 @@ attr_remove_f(
> return 0;
> }
>
> - name = argv[optind];
> + args.name = (const unsigned char *)argv[optind];
> + args.namelen = strlen(argv[optind]);
>
> - if (libxfs_iget(mp, NULL, iocur_top->ino, 0, &ip,
> + if (libxfs_iget(mp, NULL, iocur_top->ino, 0, &args.dp,
> &xfs_default_ifork_ops)) {
> dbprintf(_("failed to iget inode %llu\n"),
> (unsigned long long)iocur_top->ino);
> goto out;
> }
>
> - args.dp = ip;
> - args.name = (unsigned char *)name;
> - args.namelen = strlen(name);
> - args.value = NULL;
> -
> if (libxfs_attr_set(&args)) {
> dbprintf(_("failed to remove attr %s from inode %llu\n"),
> - name, (unsigned long long)iocur_top->ino);
> + (unsigned char *)args.name,
> + (unsigned long long)iocur_top->ino);
> goto out;
> }
>
> @@ -248,7 +237,7 @@ attr_remove_f(
>
> out:
> mp->m_flags &= ~LIBXFS_MOUNT_COMPAT_ATTR;
> - if (ip)
> - libxfs_irele(ip);
> + if (args.dp)
> + libxfs_irele(args.dp);
> return 0;
> }
> --
> 2.26.2
>
next prev parent reply other threads:[~2020-05-09 17:08 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-09 17:01 misc xfsprogs cleanups after the 5.7 merge Christoph Hellwig
2020-05-09 17:01 ` [PATCH 1/8] libxfs: use tabs instead of spaces in div_u64 Christoph Hellwig
2020-05-09 17:06 ` Darrick J. Wong
2020-05-09 17:08 ` Eric Sandeen
2020-05-09 17:01 ` [PATCH 2/8] db: fix a comment in scan_freelist Christoph Hellwig
2020-05-09 17:06 ` Darrick J. Wong
2020-05-09 17:01 ` [PATCH 3/8] db: add a comment to agfl_crc_flds Christoph Hellwig
2020-05-09 17:07 ` Darrick J. Wong
2020-05-09 17:10 ` Christoph Hellwig
2020-05-09 17:32 ` Eric Sandeen
2020-05-09 19:18 ` Darrick J. Wong
2020-05-10 7:11 ` Christoph Hellwig
2020-05-09 17:01 ` [PATCH 4/8] db: cleanup attr_set_f and attr_remove_f Christoph Hellwig
2020-05-09 17:08 ` Darrick J. Wong [this message]
2020-05-09 17:23 ` Eric Sandeen
2020-05-10 7:11 ` Christoph Hellwig
2020-05-10 14:09 ` Eric Sandeen
2020-05-11 3:41 ` Darrick J. Wong
2020-05-11 13:21 ` Eric Sandeen
2020-05-09 17:01 ` [PATCH 5/8] db: validate name and namelen in " Christoph Hellwig
2020-05-09 17:09 ` Darrick J. Wong
2020-05-09 17:12 ` Christoph Hellwig
2020-05-09 17:01 ` [PATCH 6/8] db: ensure that create and replace are exclusive in attr_set_f Christoph Hellwig
2020-05-09 17:09 ` Darrick J. Wong
2020-05-09 17:01 ` [PATCH 7/8] repair: cleanup build_agf_agfl Christoph Hellwig
2020-05-09 17:11 ` Darrick J. Wong
2020-05-09 17:47 ` Eric Sandeen
2020-05-09 17:01 ` [PATCH 8/8] metadump: small cleanup for process_inode Christoph Hellwig
2020-05-09 17:11 ` Darrick J. Wong
2020-05-09 19:03 ` misc xfsprogs cleanups after the 5.7 merge Eric Sandeen
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=20200509170800.GR6714@magnolia \
--to=darrick.wong@oracle.com \
--cc=hch@lst.de \
--cc=linux-xfs@vger.kernel.org \
--cc=sandeen@sandeen.net \
/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