From: Richard Knutsson <ricknu-0@student.ltu.se>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/3] ipc: Convert handmade 'max' to max().
Date: Fri, 04 Jan 2008 06:46:44 +0000 [thread overview]
Message-ID: <477DD654.1010709@student.ltu.se> (raw)
In-Reply-To: <20071222022701.1ddd2ae2.akpm@linux-foundation.org>
Sorry for the late response, have been away during the holidays.
Andrew Morton wrote:
> On Mon, 17 Dec 2007 03:35:55 +0100 (MET) Richard Knutsson <ricknu-0@student.ltu.se> wrote:
>
>
>> Convert handmade 'max' to max().
>>
>> ...
>>
>> --- a/ipc/msg.c
>> +++ b/ipc/msg.c
>> @@ -473,7 +473,7 @@ asmlinkage long sys_msgctl(int msqid, int cmd, struct msqid_ds __user *buf)
>> up_read(&msg_ids(ns).rw_mutex);
>> if (copy_to_user(buf, &msginfo, sizeof(struct msginfo)))
>> return -EFAULT;
>> - return (max_id < 0) ? 0 : max_id;
>> + return max(max_id, 0);
>>
>
> I don't think I like that much.
>
> I tend to think of max() as being an arithmetic sort of thing: pick the
> largest of two scalars.
>
> But the code which you're changing is a _logical_ operation. It says "if
> ipc_get_maxid() returned an error, then return zero. Otherwise return
> whatever ipc_get_maxid() returned".
>
> Yes, max() will do the right thing here, but I think it's a bit of weird
> trick?
>
>
> I mean, if ipc_get_maxid() were a better function, it would return a -ve
> errno when something failed rather than the present dopey hard-coded -1.
> In which case the code would read
>
> return IS_ERR_VALUE(max_id) ? 0 : max_id;
>
> in which case, converting it to max() would be even less appropriate. If
> you see what I mean...
>
Yes, have to agree. Were too quick with the changing...
Thanks
Richard Knutsson
WARNING: multiple messages have this Message-ID (diff)
From: Richard Knutsson <ricknu-0@student.ltu.se>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/3] ipc: Convert handmade 'max' to max().
Date: Fri, 04 Jan 2008 07:46:44 +0100 [thread overview]
Message-ID: <477DD654.1010709@student.ltu.se> (raw)
In-Reply-To: <20071222022701.1ddd2ae2.akpm@linux-foundation.org>
Sorry for the late response, have been away during the holidays.
Andrew Morton wrote:
> On Mon, 17 Dec 2007 03:35:55 +0100 (MET) Richard Knutsson <ricknu-0@student.ltu.se> wrote:
>
>
>> Convert handmade 'max' to max().
>>
>> ...
>>
>> --- a/ipc/msg.c
>> +++ b/ipc/msg.c
>> @@ -473,7 +473,7 @@ asmlinkage long sys_msgctl(int msqid, int cmd, struct msqid_ds __user *buf)
>> up_read(&msg_ids(ns).rw_mutex);
>> if (copy_to_user(buf, &msginfo, sizeof(struct msginfo)))
>> return -EFAULT;
>> - return (max_id < 0) ? 0 : max_id;
>> + return max(max_id, 0);
>>
>
> I don't think I like that much.
>
> I tend to think of max() as being an arithmetic sort of thing: pick the
> largest of two scalars.
>
> But the code which you're changing is a _logical_ operation. It says "if
> ipc_get_maxid() returned an error, then return zero. Otherwise return
> whatever ipc_get_maxid() returned".
>
> Yes, max() will do the right thing here, but I think it's a bit of weird
> trick?
>
>
> I mean, if ipc_get_maxid() were a better function, it would return a -ve
> errno when something failed rather than the present dopey hard-coded -1.
> In which case the code would read
>
> return IS_ERR_VALUE(max_id) ? 0 : max_id;
>
> in which case, converting it to max() would be even less appropriate. If
> you see what I mean...
>
Yes, have to agree. Were too quick with the changing...
Thanks
Richard Knutsson
next prev parent reply other threads:[~2008-01-04 6:46 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-12-17 2:35 [PATCH 1/3] ipc: Convert handmade 'max' to max() Richard Knutsson
2007-12-17 2:35 ` Richard Knutsson
2007-12-17 2:36 ` [PATCH 2/3] msg.h: Convert m_ts from int to size_t Richard Knutsson
2007-12-17 2:36 ` Richard Knutsson
2007-12-22 10:31 ` Andrew Morton
2007-12-22 10:31 ` Andrew Morton
2007-12-17 2:36 ` [PATCH 3/3] ipc: Convert handmade 'min' to min() Richard Knutsson
2007-12-17 2:36 ` Richard Knutsson
2007-12-22 10:27 ` [PATCH 1/3] ipc: Convert handmade 'max' to max() Andrew Morton
2007-12-22 10:27 ` Andrew Morton
2008-01-04 6:46 ` Richard Knutsson [this message]
2008-01-04 6:46 ` Richard Knutsson
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=477DD654.1010709@student.ltu.se \
--to=ricknu-0@student.ltu.se \
--cc=akpm@linux-foundation.org \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.