ipc: Convert handmade 'max' to max().
PATCH 1/3 ipc: Convert handmade 'max' to max().
Convert handmade 'max' to max().
---
msg.c | 2 +- sem.c | 2 +- shm.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
ipc/msg.c +1 -1
@@ -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 ); }case MSG_STAT :/* msqid is an index rather than a msg queue id */ case IPC_STAT :
ipc/sem.c +1 -1
@@ -641,7 +641,7 @@ static int semctl_nolock(struct ipc_namespace *ns, int semid, int semnum,up_read (&sem_ids (ns).rw_mutex);if (copy_to_user (arg.__buf, &seminfo,sizeof (struct seminfo )))return -EFAULT ; -return (max_id <0 ) ?0 : max_id; +return max (max_id,0 ); }case SEM_STAT : {
ipc/shm.c +1 -1
@@ -704,7 +704,7 @@ asmlinkage long sys_shmctl (int shmid, int cmd, struct shmid_ds __user *buf) goto out; } - err = err <0 ?0 : err; + err =max (err,0 ); goto out; }case SHM_STAT :
PATCH 2/3 msg.h: Convert m_ts from int to size_t.
Convert m_ts ("message text size") from int to size_t.
---
Remove some trailing spaces, since we are in the neighborhood.
include/linux/msg.h +2 -2
@@ -67,8 +67,8 @@ struct msginfo {/* one msg_msg structure for each message */ struct msg_msg {struct list_head m_list; -long m_type; -int m_ts;/* message text size */ +long m_type; +size_t m_ts;/* message text size */ struct msg_msgseg * next;void *security;/* the actual message follows immediately */
Re: [PATCH 2/3] msg.h: Convert m_ts from int to size_t.
Quoted 12 lines · On Mon, 17 Dec 2007 03:36:00 +0100 (MET) Richard Knutsson…
Convert
m_ts("message text size") from int tosize_t.Signed-off-by Richard Knutsson <[email protected]>---
Remove some trailing spaces, since we are in the neighborhood.include/linux/msg.h +0
-0
include/linux/msg.h struct msginfo { · line 74
Quoted 10 lines
include/linux/msg.h +2
-2@@ -67,8 +67,8 @@ struct msginfo {/* one msg_msg structure for each message */ struct msg_msg {struct list_head m_list; -long m_type; -int m_ts;/* message text size */ +long m_type; +size_t m_ts;/* message text size */ struct msg_msgseg * next;void *security;/* the actual message follows immediately */
hm, spose so. But if we're to do this then we'd need to fix qsize and r_maxsize and various other things. And we'd need to convert msg_bytes to atomic_size_t, which would prove interesting ;)
So this is at best a partial conversion and the code in there does need careful checking for the use of appropriate types. Does this patch get us partway toward the proper solution? Dunno - someone would need to sit down and work out what the best types are for all those related things.
PATCH 3/3 ipc: Convert handmade 'min' to min().
In reply to Richard KnutssonConvert handmade 'min' to min().
---
Dependent on 'msg->m_ts' being changed from int to size_t.
ipc/msg.c +1 -1
@@ -920,7 +920,7 @@ out_unlock:if (IS_ERR (msg))return PTR_ERR (msg); - msgsz = (msgsz > msg->m_ts) ? msg->m_ts : msgsz; + msgsz =min (msgsz, msg->m_ts); *pmtype = msg->m_type;if (store_msg (mtext, msg, msgsz)) msgsz = -EFAULT ;
ipc/msg.c asmlinkage long sys_msgctl(int msqid, int cmd, struct msqid_ds __user *buf) · line 476
Quoted 12 lines · On Mon, 17 Dec 2007 03:35:55 +0100 (MET) Richard Knutsson…
Convert handmade 'max' to
max()....
ipc/msg.c +1
-1@@ -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...
Sorry for the late response, have been away during the holidays.
Quoted 30 lines · Andrew Morton
ipc/msg.c asmlinkage long sys_msgctl(int msqid, int cmd, struct msqid_ds __user *buf) · line 477
Quoted 13 lines · On Mon, 17 Dec 2007 03:35:55 +0100 (MET) Richard Knutsson…
Convert handmade 'max' to
max()....
ipc/msg.c +1
-1@@ -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 whateveripc_get_maxid()returned".Yes,
max()will do the right thing here, but I think it's a bit of weird trick?
Quoted 9 lines
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 readreturn 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