mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: NeilBrown <neilb@suse.com>
To: Justin Skists <j.skists@gmail.com>, devel@driverdev.osuosl.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Patrick Farrell <paf@cray.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] staging: lustre: Fix unneeded byte-ordering cast
Date: Tue, 20 Mar 2018 12:06:45 +1100	[thread overview]
Message-ID: <87lgena72y.fsf@notabene.neil.brown.name> (raw)
In-Reply-To: <20180317091530.GA18271@tanglefoot>


[-- Attachment #1.1: Type: text/plain, Size: 2203 bytes --]

On Sat, Mar 17 2018, Justin Skists wrote:

> Fix sparse warning:
>
>   CHECK   drivers/staging//lustre/lnet/lnet/acceptor.c
> drivers/staging//lustre/lnet/lnet/acceptor.c:243:30: warning: cast to
> restricted __le32
>
> LNET_PROTO_TCP_MAGIC, as a define, is already CPU byte-ordered when
> compared to 'magic', so no need for a cast.
>
> Signed-off-by: Justin Skists <j.skists@gmail.com>
> ---
>  drivers/staging/lustre/lnet/lnet/acceptor.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/staging/lustre/lnet/lnet/acceptor.c b/drivers/staging/lustre/lnet/lnet/acceptor.c
> index fb478e20e204..13e981781b9a 100644
> --- a/drivers/staging/lustre/lnet/lnet/acceptor.c
> +++ b/drivers/staging/lustre/lnet/lnet/acceptor.c
> @@ -240,7 +240,7 @@ lnet_accept(struct socket *sock, __u32 magic)
>  			return -EPROTO;
>  		}
>  
> -		if (magic == le32_to_cpu(LNET_PROTO_TCP_MAGIC))
> +		if (magic == LNET_PROTO_TCP_MAGIC)
>  			str = "'old' socknal/tcpnal";
>  		else
>  			str = "unrecognised";

This code is almost completely irrelevant (it just choose which error
message to use when failing), but we may as well get it right and I
cannot see why your change is a fix.

"magic" was passed as an argument from lnet_acceptor() to lnet_accept(),
and lnet_acceptor() got it by reading bytes off the network with
lnet_sock_read().
My knowledge is far from complete, but from what I've seen, lustre sends
data in host-byte-order on the sender, and expects the receiver to
determine which byte-order that is (often by looking at a "magic" word
like this) and do any byte-swap that is necessary.

While I agree that LNET_PROTO_TCP_MAGIC is in host-byte-order so calling
le32_to_cpu() on it makes no sense, I don't agree that "magic" is also
host byte-ordered.

I suspect a more correct fix would be to use
  lnet_accept_magic(magic, LNET_PROTO_TCP_MAGIC)
as the condition of the if().  This is consistent with other code that
tests magic, and it is consistent with the general understanding that
"magic" should be in host-byte-order for the peer which sent the
message.
  
Could you resubmit with that change?

Thanks,
NeilBrown

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

[-- Attachment #2: Type: text/plain, Size: 169 bytes --]

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

  reply	other threads:[~2018-03-20  1:06 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-17  9:15 Justin Skists
2018-03-20  1:06 ` NeilBrown [this message]
2018-03-20 15:50   ` Justin Skists

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=87lgena72y.fsf@notabene.neil.brown.name \
    --to=neilb@suse.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=j.skists@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=paf@cray.com \
    /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

Powered by JetHome