diff mbox

[1/1,linux-next] affs: add default case in switch

Message ID 1430592980-28856-1-git-send-email-fabf@skynet.be (mailing list archive)
State New, archived
Headers show

Commit Message

Fabian Frederick May 2, 2015, 6:56 p.m. UTC
Fix gcc -Wswitch-default warnings

Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Fabian Frederick <fabf@skynet.be>
---
 fs/affs/inode.c | 2 ++
 fs/affs/namei.c | 3 +++
 2 files changed, 5 insertions(+)

Comments

Richard Weinberger May 3, 2015, 2:51 p.m. UTC | #1
On Sat, May 2, 2015 at 8:56 PM, Fabian Frederick <fabf@skynet.be> wrote:
> Fix gcc -Wswitch-default warnings
>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Signed-off-by: Fabian Frederick <fabf@skynet.be>
> ---
>  fs/affs/inode.c | 2 ++
>  fs/affs/namei.c | 3 +++
>  2 files changed, 5 insertions(+)
>
> diff --git a/fs/affs/inode.c b/fs/affs/inode.c
> index 1734950..623398e 100644
> --- a/fs/affs/inode.c
> +++ b/fs/affs/inode.c
> @@ -143,6 +143,8 @@ struct inode *affs_iget(struct super_block *sb, unsigned long ino)
>                 inode->i_op = &affs_symlink_inode_operations;
>                 inode->i_data.a_ops = &affs_symlink_aops;
>                 break;
> +       default:
> +               break;
>         }
>
>         inode->i_mtime.tv_sec = inode->i_atime.tv_sec = inode->i_ctime.tv_sec
> diff --git a/fs/affs/namei.c b/fs/affs/namei.c
> index 181e05b..517926d 100644
> --- a/fs/affs/namei.c
> +++ b/fs/affs/namei.c
> @@ -237,6 +237,9 @@ affs_lookup(struct inode *dir, struct dentry *dentry, unsigned int flags)
>                 //case ST_LINKDIR:
>                 case ST_LINKFILE:
>                         ino = be32_to_cpu(AFFS_TAIL(sb, bh)->original);
> +                       break;
> +               default:
> +                       break;

How can this code path be reached?
If I read your patch correctly it just silences gcc.

If the code can be reached you need to take a proper action of not the
warning is bogus.
Fabian Frederick May 3, 2015, 6:15 p.m. UTC | #2
> On 03 May 2015 at 16:51 Richard Weinberger <richard.weinberger@gmail.com>
> wrote:
>
>
> On Sat, May 2, 2015 at 8:56 PM, Fabian Frederick <fabf@skynet.be> wrote:
> > Fix gcc -Wswitch-default warnings
> >
> > Cc: Andrew Morton <akpm@linux-foundation.org>
> > Signed-off-by: Fabian Frederick <fabf@skynet.be>
> > ---
> >  fs/affs/inode.c | 2 ++
> >  fs/affs/namei.c | 3 +++
> >  2 files changed, 5 insertions(+)
> >
> > diff --git a/fs/affs/inode.c b/fs/affs/inode.c
> > index 1734950..623398e 100644
> > --- a/fs/affs/inode.c
> > +++ b/fs/affs/inode.c
> > @@ -143,6 +143,8 @@ struct inode *affs_iget(struct super_block *sb, unsigned
> > long ino)
> >                 inode->i_op = &affs_symlink_inode_operations;
> >                 inode->i_data.a_ops = &affs_symlink_aops;
> >                 break;
> > +       default:
> > +               break;
> >         }
> >
> >         inode->i_mtime.tv_sec = inode->i_atime.tv_sec =
> >inode->i_ctime.tv_sec
> > diff --git a/fs/affs/namei.c b/fs/affs/namei.c
> > index 181e05b..517926d 100644
> > --- a/fs/affs/namei.c
> > +++ b/fs/affs/namei.c
> > @@ -237,6 +237,9 @@ affs_lookup(struct inode *dir, struct dentry *dentry,
> > unsigned int flags)
> >                 //case ST_LINKDIR:
> >                 case ST_LINKFILE:
> >                         ino = be32_to_cpu(AFFS_TAIL(sb, bh)->original);
> > +                       break;
> > +               default:
> > +                       break;
>
> How can this code path be reached?
> If I read your patch correctly it just silences gcc.
>
> If the code can be reached you need to take a proper action of not the
> warning is bogus.

As far as I understand, switch in affs_lookup() only updates inode number when
it's a link so we can simply add default:break to silence gcc warning or replace
by if().

affs_iget() switch on the other hand applies to any type of file.
Maybe we could add default: BUG() to avoid working on bad inode ?

Regards,
Fabian
>
> --
> Thanks,
> //richard
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Richard Weinberger May 3, 2015, 6:23 p.m. UTC | #3
Am 03.05.2015 um 20:15 schrieb Fabian Frederick:
>> If the code can be reached you need to take a proper action of not the
>> warning is bogus.
> 
> As far as I understand, switch in affs_lookup() only updates inode number when
> it's a link so we can simply add default:break to silence gcc warning or replace
> by if().

Does the warning trigger with our default set of compiler warnings?
Not all gcc warnings are useful. :)

> affs_iget() switch on the other hand applies to any type of file.
> Maybe we could add default: BUG() to avoid working on bad inode ?

Or cancel the operation and return -EIO to userspace.

Thanks,
//richard
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Fabian Frederick May 3, 2015, 6:38 p.m. UTC | #4
> On 03 May 2015 at 20:23 Richard Weinberger <richard@nod.at> wrote:
>
>
> Am 03.05.2015 um 20:15 schrieb Fabian Frederick:
> >> If the code can be reached you need to take a proper action of not the
> >> warning is bogus.
> >
> > As far as I understand, switch in affs_lookup() only updates inode number
> > when
> > it's a link so we can simply add default:break to silence gcc warning or
> > replace
> > by if().
>
> Does the warning trigger with our default set of compiler warnings?
> Not all gcc warnings are useful. :)
Only with W=123

>
> > affs_iget() switch on the other hand applies to any type of file.
> > Maybe we could add default: BUG() to avoid working on bad inode ?
>
> Or cancel the operation and return -EIO to userspace.
Ok, thanks, I'll send another version :)

Regards,
Fabian
>
> Thanks,
> //richard
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Richard Weinberger May 3, 2015, 6:39 p.m. UTC | #5
Am 03.05.2015 um 20:38 schrieb Fabian Frederick:
> 
> 
>> On 03 May 2015 at 20:23 Richard Weinberger <richard@nod.at> wrote:
>>
>>
>> Am 03.05.2015 um 20:15 schrieb Fabian Frederick:
>>>> If the code can be reached you need to take a proper action of not the
>>>> warning is bogus.
>>>
>>> As far as I understand, switch in affs_lookup() only updates inode number
>>> when
>>> it's a link so we can simply add default:break to silence gcc warning or
>>> replace
>>> by if().
>>
>> Does the warning trigger with our default set of compiler warnings?
>> Not all gcc warnings are useful. :)
> Only with W=123
> 
>>
>>> affs_iget() switch on the other hand applies to any type of file.
>>> Maybe we could add default: BUG() to avoid working on bad inode ?
>>
>> Or cancel the operation and return -EIO to userspace.
> Ok, thanks, I'll send another version :)

As the warning happens only with W=123 I'd ignore it. :)

Thanks,
//richard
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/fs/affs/inode.c b/fs/affs/inode.c
index 1734950..623398e 100644
--- a/fs/affs/inode.c
+++ b/fs/affs/inode.c
@@ -143,6 +143,8 @@  struct inode *affs_iget(struct super_block *sb, unsigned long ino)
 		inode->i_op = &affs_symlink_inode_operations;
 		inode->i_data.a_ops = &affs_symlink_aops;
 		break;
+	default:
+		break;
 	}
 
 	inode->i_mtime.tv_sec = inode->i_atime.tv_sec = inode->i_ctime.tv_sec
diff --git a/fs/affs/namei.c b/fs/affs/namei.c
index 181e05b..517926d 100644
--- a/fs/affs/namei.c
+++ b/fs/affs/namei.c
@@ -237,6 +237,9 @@  affs_lookup(struct inode *dir, struct dentry *dentry, unsigned int flags)
 		//case ST_LINKDIR:
 		case ST_LINKFILE:
 			ino = be32_to_cpu(AFFS_TAIL(sb, bh)->original);
+			break;
+		default:
+			break;
 		}
 		affs_brelse(bh);
 		inode = affs_iget(sb, ino);