2006-09-17 01:47:32

by Josef 'Jeff' Sipek

[permalink] [raw]
Subject: [PATCH 0 of 11] Use SEEK_{SET,CUR,END} instead of hardcoded values

In July, David Howells added SEEK_{SET,CUR,END} definitions to include/linux/fs.h

The following patches convert offenders which were found by grep'ing the source
tree.

Josef 'Jeff' Sipek

11 files changed, 34 insertions(+), 39 deletions(-)
drivers/char/mbcs.c | 7 ++++---
drivers/isdn/hardware/eicon/dsp_defs.h | 3 ---
drivers/mtd/mtdchar.c | 11 ++++-------
fs/cifs/cifsfs.c | 2 +-
fs/locks.c | 12 ++++++------
fs/nfs/file.c | 2 +-
fs/xfs/xfs_vnodeops.c | 6 +++---
sound/core/info.c | 6 +++---
sound/drivers/opl4/opl4_proc.c | 6 +++---
sound/isa/gus/gus_mem_proc.c | 6 +++---
sound/pci/mixart/mixart.c | 12 ++++++------




2006-09-17 01:47:53

by Josef 'Jeff' Sipek

[permalink] [raw]
Subject: [PATCH 8 of 11] sound core: Use SEEK_{SET, CUR, END} instead of hardcoded values

sound core: Use SEEK_{SET,CUR,END} instead of hardcoded values

Signed-off-by: Josef 'Jeff' Sipek <[email protected]>

--

diff -r 1622a39ffb54 -r 7e68f25a3e0c sound/core/info.c
--- a/sound/core/info.c Sat Sep 16 21:00:45 2006 -0400
+++ b/sound/core/info.c Sat Sep 16 21:00:45 2006 -0400
@@ -174,15 +174,15 @@ static loff_t snd_info_entry_llseek(stru
switch (entry->content) {
case SNDRV_INFO_CONTENT_TEXT:
switch (orig) {
- case 0: /* SEEK_SET */
+ case SEEK_SET:
file->f_pos = offset;
ret = file->f_pos;
goto out;
- case 1: /* SEEK_CUR */
+ case SEEK_CUR:
file->f_pos += offset;
ret = file->f_pos;
goto out;
- case 2: /* SEEK_END */
+ case SEEK_END:
default:
ret = -EINVAL;
goto out;


2006-09-17 01:47:36

by Josef 'Jeff' Sipek

[permalink] [raw]
Subject: [PATCH 1 of 11] MBCS: Use SEEK_{SET, CUR, END} instead of hardcoded values

MBCS: Use SEEK_{SET,CUR,END} instead of hardcoded values

Signed-off-by: Josef 'Jeff' Sipek <[email protected]>

--

diff -r abfba7cd6289 -r 115dd6f4c050 drivers/char/mbcs.c
--- a/drivers/char/mbcs.c Sun Sep 17 02:54:32 2006 +0700
+++ b/drivers/char/mbcs.c Sat Sep 16 21:00:45 2006 -0400
@@ -22,6 +22,7 @@
#include <linux/delay.h>
#include <linux/device.h>
#include <linux/mm.h>
+#include <linux/fs.h>
#include <linux/uio.h>
#include <asm/io.h>
#include <asm/uaccess.h>
@@ -447,15 +448,15 @@ loff_t mbcs_sram_llseek(struct file * fi
loff_t newpos;

switch (whence) {
- case 0: /* SEEK_SET */
+ case SEEK_SET:
newpos = off;
break;

- case 1: /* SEEK_CUR */
+ case SEEK_CUR:
newpos = filp->f_pos + off;
break;

- case 2: /* SEEK_END */
+ case SEEK_END:
newpos = MBCS_SRAM_SIZE + off;
break;



2006-09-17 01:48:05

by Josef 'Jeff' Sipek

[permalink] [raw]
Subject: [PATCH 9 of 11] opl4: Use SEEK_{SET, CUR, END} instead of hardcoded values

opl4: Use SEEK_{SET,CUR,END} instead of hardcoded values

Signed-off-by: Josef 'Jeff' Sipek <[email protected]>

--

diff -r 7e68f25a3e0c -r 057a40d60798 sound/drivers/opl4/opl4_proc.c
--- a/sound/drivers/opl4/opl4_proc.c Sat Sep 16 21:00:45 2006 -0400
+++ b/sound/drivers/opl4/opl4_proc.c Sat Sep 16 21:00:46 2006 -0400
@@ -105,13 +105,13 @@ static long long snd_opl4_mem_proc_llsee
struct file *file, long long offset, int orig)
{
switch (orig) {
- case 0: /* SEEK_SET */
+ case SEEK_SET:
file->f_pos = offset;
break;
- case 1: /* SEEK_CUR */
+ case SEEK_CUR:
file->f_pos += offset;
break;
- case 2: /* SEEK_END, offset is negative */
+ case SEEK_END: /* offset is negative */
file->f_pos = entry->size + offset;
break;
default:


2006-09-17 01:48:33

by Josef 'Jeff' Sipek

[permalink] [raw]
Subject: [PATCH 10 of 11] gus: Use SEEK_{SET, CUR, END} instead of hardcoded values

gus: Use SEEK_{SET,CUR,END} instead of hardcoded values

Signed-off-by: Josef 'Jeff' Sipek <[email protected]>

--

diff -r 057a40d60798 -r f255d0d208e7 sound/isa/gus/gus_mem_proc.c
--- a/sound/isa/gus/gus_mem_proc.c Sat Sep 16 21:00:46 2006 -0400
+++ b/sound/isa/gus/gus_mem_proc.c Sat Sep 16 21:00:46 2006 -0400
@@ -61,13 +61,13 @@ static long long snd_gf1_mem_proc_llseek
struct gus_proc_private *priv = entry->private_data;

switch (orig) {
- case 0: /* SEEK_SET */
+ case SEEK_SET:
file->f_pos = offset;
break;
- case 1: /* SEEK_CUR */
+ case SEEK_CUR:
file->f_pos += offset;
break;
- case 2: /* SEEK_END, offset is negative */
+ case SEEK_END: /* offset is negative */
file->f_pos = priv->size + offset;
break;
default:


2006-09-17 01:49:14

by Josef 'Jeff' Sipek

[permalink] [raw]
Subject: [PATCH 5 of 11] XFS: Use SEEK_{SET, CUR, END} instead of hardcoded values

XFS: Use SEEK_{SET,CUR,END} instead of hardcoded values

Signed-off-by: Josef 'Jeff' Sipek <[email protected]>

--

diff -r e2fae9fe7a30 -r 4cdee5980dad fs/xfs/xfs_vnodeops.c
--- a/fs/xfs/xfs_vnodeops.c Sat Sep 16 21:00:45 2006 -0400
+++ b/fs/xfs/xfs_vnodeops.c Sat Sep 16 21:00:45 2006 -0400
@@ -4510,12 +4510,12 @@ xfs_change_file_space(
xfs_iunlock(ip, XFS_ILOCK_SHARED);

switch (bf->l_whence) {
- case 0: /*SEEK_SET*/
+ case SEEK_SET:
break;
- case 1: /*SEEK_CUR*/
+ case SEEK_CUR:
bf->l_start += offset;
break;
- case 2: /*SEEK_END*/
+ case SEEK_END:
bf->l_start += ip->i_d.di_size;
break;
default:


2006-09-17 01:48:48

by Josef 'Jeff' Sipek

[permalink] [raw]
Subject: [PATCH 4 of 11] CIFS: Use SEEK_END instead of hardcoded value

CIFS: Use SEEK_END instead of hardcoded value

Signed-off-by: Josef 'Jeff' Sipek <[email protected]>

--

diff -r 7d3e8ba1ace3 -r e2fae9fe7a30 fs/cifs/cifsfs.c
--- a/fs/cifs/cifsfs.c Sat Sep 16 21:00:45 2006 -0400
+++ b/fs/cifs/cifsfs.c Sat Sep 16 21:00:45 2006 -0400
@@ -510,7 +510,7 @@ static loff_t cifs_llseek(struct file *f
static loff_t cifs_llseek(struct file *file, loff_t offset, int origin)
{
/* origin == SEEK_END => we must revalidate the cached file length */
- if (origin == 2) {
+ if (origin == SEEK_END) {
int retval = cifs_revalidate(file->f_dentry);
if (retval < 0)
return (loff_t)retval;


2006-09-17 01:48:49

by Josef 'Jeff' Sipek

[permalink] [raw]
Subject: [PATCH 11 of 11] mixart: Use SEEK_{SET, CUR, END} instead of hardcoded values

mixart: Use SEEK_{SET,CUR,END} instead of hardcoded values

Signed-off-by: Josef 'Jeff' Sipek <[email protected]>

--

diff -r f255d0d208e7 -r 9ef3df8b70fe sound/pci/mixart/mixart.c
--- a/sound/pci/mixart/mixart.c Sat Sep 16 21:00:46 2006 -0400
+++ b/sound/pci/mixart/mixart.c Sat Sep 16 21:00:46 2006 -0400
@@ -1109,13 +1109,13 @@ static long long snd_mixart_BA0_llseek(s
offset = offset & ~3; /* 4 bytes aligned */

switch(orig) {
- case 0: /* SEEK_SET */
+ case SEEK_SET:
file->f_pos = offset;
break;
- case 1: /* SEEK_CUR */
+ case SEEK_CUR:
file->f_pos += offset;
break;
- case 2: /* SEEK_END, offset is negative */
+ case SEEK_END: /* offset is negative */
file->f_pos = MIXART_BA0_SIZE + offset;
break;
default:
@@ -1135,13 +1135,13 @@ static long long snd_mixart_BA1_llseek(s
offset = offset & ~3; /* 4 bytes aligned */

switch(orig) {
- case 0: /* SEEK_SET */
+ case SEEK_SET:
file->f_pos = offset;
break;
- case 1: /* SEEK_CUR */
+ case SEEK_CUR:
file->f_pos += offset;
break;
- case 2: /* SEEK_END, offset is negative */
+ case SEEK_END: /* offset is negative */
file->f_pos = MIXART_BA1_SIZE + offset;
break;
default:


2006-09-17 01:49:57

by Josef 'Jeff' Sipek

[permalink] [raw]
Subject: [PATCH 6 of 11] NFS: Use SEEK_END instead of hardcoded value

NFS: Use SEEK_END instead of hardcoded value

Signed-off-by: Josef 'Jeff' Sipek <[email protected]>

--

diff -r 4cdee5980dad -r ca33dbd739b3 fs/nfs/file.c
--- a/fs/nfs/file.c Sat Sep 16 21:00:45 2006 -0400
+++ b/fs/nfs/file.c Sat Sep 16 21:00:45 2006 -0400
@@ -157,7 +157,7 @@ static loff_t nfs_file_llseek(struct fil
static loff_t nfs_file_llseek(struct file *filp, loff_t offset, int origin)
{
/* origin == SEEK_END => we must revalidate the cached file length */
- if (origin == 2) {
+ if (origin == SEEK_END) {
struct inode *inode = filp->f_mapping->host;
int retval = nfs_revalidate_file_size(inode, filp);
if (retval < 0)


2006-09-17 01:48:05

by Josef 'Jeff' Sipek

[permalink] [raw]
Subject: [PATCH 2 of 11] EICON ISDN: Removed unused definitions for OS_SEEK_*

EICON ISDN: Removed unused definitions for OS_SEEK_*

Signed-off-by: Josef 'Jeff' Sipek <[email protected]>

--

diff -r 115dd6f4c050 -r e90cdef08ec3 drivers/isdn/hardware/eicon/dsp_defs.h
--- a/drivers/isdn/hardware/eicon/dsp_defs.h Sat Sep 16 21:00:45 2006 -0400
+++ b/drivers/isdn/hardware/eicon/dsp_defs.h Sat Sep 16 21:00:45 2006 -0400
@@ -34,9 +34,6 @@
*
* I/O functions returns -1 on error, 0 on EOF
*/
-#define OS_SEEK_SET 0
-#define OS_SEEK_CUR 1
-#define OS_SEEK_END 2
struct _OsFileHandle_;
typedef long ( * OsFileIo) (struct _OsFileHandle_ *handle,
void *buffer,


2006-09-17 01:51:55

by Josef 'Jeff' Sipek

[permalink] [raw]
Subject: [PATCH 3 of 11] MTD: Use SEEK_{SET, CUR, END} instead of hardcoded values

MTD: Use SEEK_{SET,CUR,END} instead of hardcoded values

Signed-off-by: Josef 'Jeff' Sipek <[email protected]>

--

diff -r e90cdef08ec3 -r 7d3e8ba1ace3 drivers/mtd/mtdchar.c
--- a/drivers/mtd/mtdchar.c Sat Sep 16 21:00:45 2006 -0400
+++ b/drivers/mtd/mtdchar.c Sat Sep 16 21:00:45 2006 -0400
@@ -62,15 +62,12 @@ static loff_t mtd_lseek (struct file *fi
struct mtd_info *mtd = mfi->mtd;

switch (orig) {
- case 0:
- /* SEEK_SET */
- break;
- case 1:
- /* SEEK_CUR */
+ case SEEK_SET:
+ break;
+ case SEEK_CUR:
offset += file->f_pos;
break;
- case 2:
- /* SEEK_END */
+ case SEEK_END:
offset += mtd->size;
break;
default:


2006-09-17 01:51:45

by Josef 'Jeff' Sipek

[permalink] [raw]
Subject: [PATCH 7 of 11] VFS: Use SEEK_{SET, CUR, END} instead of hardcoded values

VFS: Use SEEK_{SET,CUR,END} instead of hardcoded values

Signed-off-by: Josef 'Jeff' Sipek <[email protected]>

--

diff -r ca33dbd739b3 -r 1622a39ffb54 fs/locks.c
--- a/fs/locks.c Sat Sep 16 21:00:45 2006 -0400
+++ b/fs/locks.c Sat Sep 16 21:00:45 2006 -0400
@@ -314,13 +314,13 @@ static int flock_to_posix_lock(struct fi
off_t start, end;

switch (l->l_whence) {
- case 0: /*SEEK_SET*/
+ case SEEK_SET:
start = 0;
break;
- case 1: /*SEEK_CUR*/
+ case SEEK_CUR:
start = filp->f_pos;
break;
- case 2: /*SEEK_END*/
+ case SEEK_END:
start = i_size_read(filp->f_dentry->d_inode);
break;
default:
@@ -364,13 +364,13 @@ static int flock64_to_posix_lock(struct
loff_t start;

switch (l->l_whence) {
- case 0: /*SEEK_SET*/
+ case SEEK_SET:
start = 0;
break;
- case 1: /*SEEK_CUR*/
+ case SEEK_CUR:
start = filp->f_pos;
break;
- case 2: /*SEEK_END*/
+ case SEEK_END:
start = i_size_read(filp->f_dentry->d_inode);
break;
default:


2006-09-17 03:46:30

by Nick Piggin

[permalink] [raw]
Subject: Re: [PATCH 0 of 11] Use SEEK_{SET,CUR,END} instead of hardcoded values

Josef 'Jeff' Sipek wrote:
> In July, David Howells added SEEK_{SET,CUR,END} definitions to include/linux/fs.h
>
> The following patches convert offenders which were found by grep'ing the source
> tree.

Looks like a good change to me.

Nitpick, do you need 11 patches to do it? 1 would be fine, I think?

--
SUSE Labs, Novell Inc.
Send instant messages to your online friends http://au.messenger.yahoo.com

2006-09-17 06:38:40

by Josef Sipek

[permalink] [raw]
Subject: Re: [PATCH 0 of 11] Use SEEK_{SET,CUR,END} instead of hardcoded values

On Sun, Sep 17, 2006 at 01:46:23PM +1000, Nick Piggin wrote:
> Josef 'Jeff' Sipek wrote:
> >In July, David Howells added SEEK_{SET,CUR,END} definitions to
> >include/linux/fs.h
> >
> >The following patches convert offenders which were found by grep'ing the
> >source
> >tree.
>
> Looks like a good change to me.
>
> Nitpick, do you need 11 patches to do it? 1 would be fine, I think?

I don't. I just got carried away with Mercurial's patch queues support.

Josef 'Jeff' Sipek.

--
A computer without Microsoft is like chocolate cake without mustard.

2006-09-17 08:49:21

by Armin Schindler

[permalink] [raw]
Subject: Re: [PATCH 2 of 11] EICON ISDN: Removed unused definitions for OS_SEEK_*


Agreed, these defines are not used in the linux kernel. They can be removed.

Armin

On Sat, 16 Sep 2006, Josef 'Jeff' Sipek wrote:
> EICON ISDN: Removed unused definitions for OS_SEEK_*

Acked-by: Armin Schindler <[email protected]>
Signed-off-by: Josef 'Jeff' Sipek <[email protected]>

--

diff -r 115dd6f4c050 -r e90cdef08ec3 drivers/isdn/hardware/eicon/dsp_defs.h
--- a/drivers/isdn/hardware/eicon/dsp_defs.h Sat Sep 16 21:00:45 2006 -0400
+++ b/drivers/isdn/hardware/eicon/dsp_defs.h Sat Sep 16 21:00:45 2006 -0400
@@ -34,9 +34,6 @@
*
* I/O functions returns -1 on error, 0 on EOF
*/
-#define OS_SEEK_SET 0
-#define OS_SEEK_CUR 1
-#define OS_SEEK_END 2
struct _OsFileHandle_;
typedef long ( * OsFileIo) (struct _OsFileHandle_ *handle,
void *buffer,


2006-09-17 16:06:52

by David Woodhouse

[permalink] [raw]
Subject: Re: [PATCH 3 of 11] MTD: Use SEEK_{SET, CUR, END} instead of hardcoded values

On Sat, 2006-09-16 at 21:09 -0400, Josef 'Jeff' Sipek wrote:
> MTD: Use SEEK_{SET,CUR,END} instead of hardcoded values
>
> Signed-off-by: Josef 'Jeff' Sipek <[email protected]>

Applied to MTD git tree; thanks.

--
dwmw2

2006-09-18 03:35:11

by David Chinner

[permalink] [raw]
Subject: Re: [PATCH 5 of 11] XFS: Use SEEK_{SET, CUR, END} instead of hardcoded values

On Sat, Sep 16, 2006 at 09:09:31PM -0400, Josef 'Jeff' Sipek wrote:
> XFS: Use SEEK_{SET,CUR,END} instead of hardcoded values

The hard coded values used in xfs_change_file_space() are documented as part
of the API to the userspace functions that use this interface in xfsctl(3).
That is:

XFS_IOC_FREESP
XFS_IOC_FREESP64
XFS_IOC_ALLOCSP
XFS_IOC_ALLOCSP64

Alter storage space associated with a section of the ordinary file specified.
The section is specified by a variable of type xfs_flock64_t, pointed to by
the final argument. The data type xfs_flock64_t contains the following
members: l_whence is 0, 1, or 2 to indicate that the relative offset l_start
will be measured from the start of the file, the current position, or the
end of the file, respectively.

Hence I think that the hard coded values should not be changed to something
that is defined outside of XFS's API.

Cheers,

Dave.
--
Dave Chinner
Principal Engineer
SGI Australian Software Group

2006-09-18 10:31:36

by David Howells

[permalink] [raw]
Subject: Re: [PATCH 5 of 11] XFS: Use SEEK_{SET, CUR, END} instead of hardcoded values

David Chinner <[email protected]> wrote:

> The hard coded values used in xfs_change_file_space() are documented as part
> of the API to the userspace functions that use this interface in xfsctl(3).

Hmmm... that's a good point. I think you're right on this account, and so the
comments in:

case 0: /*SEEK_SET*/
break;
case 1: /*SEEK_CUR*/
bf->l_start += offset;
break;
case 2: /*SEEK_END*/
bf->l_start += ip->i_d.di_size;
break;

should be stripped off as they are not exactly correct.

David

2006-09-18 10:32:42

by David Howells

[permalink] [raw]
Subject: Re: [PATCH 0 of 11] Use SEEK_{SET,CUR,END} instead of hardcoded values

Josef 'Jeff' Sipek <[email protected]> wrote:

> In July, David Howells added SEEK_{SET,CUR,END} definitions to
> include/linux/fs.h
>
> The following patches convert offenders which were found by grep'ing the
> source tree.

Looks good, though I think you do have to drop the XFS portion of the patch,
though you could strip the comments from the case statements there.

So NAK for the XFS patch, but for the rest:

Acked-By: David Howells <[email protected]>

2006-09-19 04:01:59

by David Chinner

[permalink] [raw]
Subject: Re: [PATCH 5 of 11] XFS: Use SEEK_{SET, CUR, END} instead of hardcoded values

On Mon, Sep 18, 2006 at 11:30:35AM +0100, David Howells wrote:
> David Chinner <[email protected]> wrote:
>
> > The hard coded values used in xfs_change_file_space() are documented as part
> > of the API to the userspace functions that use this interface in xfsctl(3).
>
> Hmmm... that's a good point. I think you're right on this account, and so the
> comments in:
>
> case 0: /*SEEK_SET*/
> break;
> case 1: /*SEEK_CUR*/
> bf->l_start += offset;
> break;
> case 2: /*SEEK_END*/
> bf->l_start += ip->i_d.di_size;
> break;
>
> should be stripped off as they are not exactly correct.

Sure, they're not _exactly_ the same as seek semantics, but the
comment is informative enough to tell you what the magic numbers
are supposed to mean as you read the code.

If you really want to strip these out these comments, can you please
replace them with a new comment that documents the magic number
behaviour?

Cheers,

Dave.
--
Dave Chinner
Principal Engineer
SGI Australian Software Group