mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Peter Xu <peterx@redhat.com>
To: Axel Rasmussen <axelrasmussen@google.com>
Cc: Shuah Khan <shuah@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Joe Perches <joe@perches.com>,
	Mike Rapoport <rppt@linux.vnet.ibm.com>,
	Andrea Arcangeli <aarcange@redhat.com>,
	David Alan Gilbert <dgilbert@redhat.com>,
	Greg Thelen <gthelen@google.com>,
	linux-kselftest@vger.kernel.org,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] userfaultfd: selftests: make __{s,u}64 format specifiers portable
Date: Wed, 2 Dec 2020 20:32:13 -0500	[thread overview]
Message-ID: <20201203013213.GE108496@xz-x1> (raw)
In-Reply-To: <CAJHvVch2LJa57-Si2prKa-S3VUPpu3jYxW+3-+tcLMgSXkB69w@mail.gmail.com>

On Wed, Dec 02, 2020 at 03:52:56PM -0800, Axel Rasmussen wrote:
> On Wed, Dec 2, 2020 at 3:10 PM Peter Xu <peterx@redhat.com> wrote:
> >
> > Hi, Axel,
> >
> > Looks mostly good to me, but a few nitpickings below.
> >
> > On Wed, Dec 02, 2020 at 01:15:42PM -0800, Axel Rasmussen wrote:
> >
> > [...]
> >
> > > +static void uffd_error(const char *message, __s64 code)
> > > +{
> > > +     fprintf(stderr, "%s: %" PRId64 "\n", message, (int64_t)code);
> > > +     exit(1);
> > > +}
> >
> > IMHO a macro that can take arbitrary parameters would be nicer, but if it
> > satisfy our need, definitely ok too.
> >
> > [...]
> >
> > > @@ -340,7 +348,8 @@ static void wp_range(int ufd, __u64 start, __u64 len, bool wp)
> > >       prms.mode = wp ? UFFDIO_WRITEPROTECT_MODE_WP : 0;
> > >
> > >       if (ioctl(ufd, UFFDIO_WRITEPROTECT, &prms)) {
> > > -             fprintf(stderr, "clear WP failed for address 0x%Lx\n", start);
> > > +             fprintf(stderr, "clear WP failed for address 0x%" PRIx64 "\n",
> > > +                     (uint64_t)start);
> > >               exit(1);
> >
> > Is it intended to not use uffd_error() here?
> 
> Yes, this is intentional. This particular case prints the value in
> hexadecimal, rather than decimal.
> 
> (Agree that uffd_error() could be made more general to cover cases
> like this. I opted for the simplest thing which covers all but two
> cases - this one, and one where we "return 1;" instead of "exit(1);" -
> but I don't feel strongly.)

Actually it's as simple as:

#define  uffd_error(...)  do {                  \
        fprintf(stderr, __VA_ARGS__);           \
        fprintf(stderr, "\n");                  \
        exit(1);                                \
    } while (0)

But it's okay, I think.

> 
> >
> > >       }
> > >  }
> >
> > [...]
> >
> > > @@ -979,26 +981,20 @@ static int __uffdio_zeropage(int ufd, unsigned long offset, bool retry)
> > >       if (ret) {
> > >               /* real retval in ufdio_zeropage.zeropage */
> > >               if (has_zeropage) {
> > > -                     if (uffdio_zeropage.zeropage == -EEXIST) {
> > > -                             fprintf(stderr, "UFFDIO_ZEROPAGE -EEXIST\n");
> > > -                             exit(1);
> > > -                     } else {
> > > -                             fprintf(stderr, "UFFDIO_ZEROPAGE error %Ld\n",
> > > -                                     uffdio_zeropage.zeropage);
> > > -                             exit(1);
> > > -                     }
> > > +                     uffd_error(uffdio_zeropage.zeropage == -EEXIST ?
> > > +                                              "UFFDIO_ZEROPAGE -EEXIST" :
> > > +                                              "UFFDIO_ZEROPAGE error",
> >
> > Nit: The indents here are a bit odd..
> 
> This is what clang-format yields. Are you thinking it would be better
> to line everything up with the ( in uffd_error( ?
> 
> Or, perhaps this case is a good reason to make uffd_error() a variadic
> macro so we can insert "-EEXIST" || "error" with a "%s".

Yes.  It fixes a build warning, so I think current patch is fine too.

No matter whether you'd like a v2, please feel free to take:

Acked-by: Peter Xu <peterx@redhat.com>

Thanks,

-- 
Peter Xu


      parent reply	other threads:[~2020-12-03  1:34 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-02 21:15 Axel Rasmussen
2020-12-02 23:09 ` Peter Xu
2020-12-02 23:52   ` Axel Rasmussen
2020-12-03  0:09     ` Miguel Ojeda
2020-12-03  1:32     ` Peter Xu [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=20201203013213.GE108496@xz-x1 \
    --to=peterx@redhat.com \
    --cc=aarcange@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=axelrasmussen@google.com \
    --cc=dgilbert@redhat.com \
    --cc=gthelen@google.com \
    --cc=joe@perches.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=rppt@linux.vnet.ibm.com \
    --cc=shuah@kernel.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

all inboxes | Powered by JetHome®