2009-12-03 08:48:33

by Cong Wang

[permalink] [raw]
Subject: [Patch] selinux: remove a useless return

The last return is unreachable, remove the 'return'
in default, let it fall through.

Signed-off-by: WANG Cong <[email protected]>
Cc: James Morris <[email protected]>
Cc: Eric Paris <[email protected]>

---

diff --git a/security/selinux/ss/mls.c b/security/selinux/ss/mls.c
index b5407f1..718823d 100644
--- a/security/selinux/ss/mls.c
+++ b/security/selinux/ss/mls.c
@@ -542,7 +542,7 @@ int mls_compute_sid(struct context *scontext,
/* Use the process effective MLS attributes. */
return mls_context_cpy_low(newcontext, scontext);
default:
- return -EINVAL;
+ /* Fallthrough */
}
return -EINVAL;
}


2009-12-03 14:24:26

by Eric Paris

[permalink] [raw]
Subject: Re: [Patch] selinux: remove a useless return

On Thu, 2009-12-03 at 03:48 -0500, Amerigo Wang wrote:
> The last return is unreachable, remove the 'return'
> in default, let it fall through.
>
> Signed-off-by: WANG Cong <[email protected]>
> Cc: James Morris <[email protected]>
> Cc: Eric Paris <[email protected]>

Acked-by: Eric Paris <[email protected]>

>
> ---
>
> diff --git a/security/selinux/ss/mls.c b/security/selinux/ss/mls.c
> index b5407f1..718823d 100644
> --- a/security/selinux/ss/mls.c
> +++ b/security/selinux/ss/mls.c
> @@ -542,7 +542,7 @@ int mls_compute_sid(struct context *scontext,
> /* Use the process effective MLS attributes. */
> return mls_context_cpy_low(newcontext, scontext);
> default:
> - return -EINVAL;
> + /* Fallthrough */
> }
> return -EINVAL;
> }

2009-12-07 13:32:24

by Dan Carpenter

[permalink] [raw]
Subject: Re: [Patch] selinux: remove a useless return

On 12/3/09, Amerigo Wang <[email protected]> wrote:
> The last return is unreachable, remove the 'return'
> in default, let it fall through.
>
> Signed-off-by: WANG Cong <[email protected]>
> Cc: James Morris <[email protected]>
> Cc: Eric Paris <[email protected]>
>
> ---
>
> diff --git a/security/selinux/ss/mls.c b/security/selinux/ss/mls.c
> index b5407f1..718823d 100644
> --- a/security/selinux/ss/mls.c
> +++ b/security/selinux/ss/mls.c
> @@ -542,7 +542,7 @@ int mls_compute_sid(struct context *scontext,
> /* Use the process effective MLS attributes. */
> return mls_context_cpy_low(newcontext, scontext);
> default:
> - return -EINVAL;
> + /* Fallthrough */
> }
> return -EINVAL;
> }

I don't think this compiles. GCC doesn't let you end a switch block
with a label.

I also have sent the selinux people a patch that didn't compile by
mistake. Afterward I wrote this script so hopefully I won't mess up
again.

#!/bin/bash -e

files=$(grep +++ /home/dcarpenter/var/mail/postponed-msgs | cut -f 1 |
cut -b 5-)
for file in $files ; do
file=${file/devel\//}
file=${file/new\//}
kchecker $file
if which sparse | grep -q sparse ; then
kchecker --sparse $file
fi
done


You will have to change the path names. Hm.... Also you will have to
get the kchecker script from the smatch_data/ directory of smatch
(http://repo.or.cz/w/smatch.git).

regards,
dan carpenter

2009-12-07 22:27:16

by James Morris

[permalink] [raw]
Subject: Re: [Patch] selinux: remove a useless return

On Thu, 3 Dec 2009, Amerigo Wang wrote:

> The last return is unreachable, remove the 'return'
> in default, let it fall through.
>
> Signed-off-by: WANG Cong <[email protected]>
> Cc: James Morris <[email protected]>
> Cc: Eric Paris <[email protected]>


Applied to
git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/security-testing-2.6#next

with a fixup for the problem reported by Dan Carpenter.

You should not send out patches without testing them, even when following
the advice of the person you're sending them to :-)


--
James Morris
<[email protected]>

2009-12-08 09:52:03

by Cong Wang

[permalink] [raw]
Subject: Re: [Patch] selinux: remove a useless return

Dan Carpenter wrote:
> On 12/3/09, Amerigo Wang <[email protected]> wrote:
>> The last return is unreachable, remove the 'return'
>> in default, let it fall through.
>>
>> Signed-off-by: WANG Cong <[email protected]>
>> Cc: James Morris <[email protected]>
>> Cc: Eric Paris <[email protected]>
>>
>> ---
>>
>> diff --git a/security/selinux/ss/mls.c b/security/selinux/ss/mls.c
>> index b5407f1..718823d 100644
>> --- a/security/selinux/ss/mls.c
>> +++ b/security/selinux/ss/mls.c
>> @@ -542,7 +542,7 @@ int mls_compute_sid(struct context *scontext,
>> /* Use the process effective MLS attributes. */
>> return mls_context_cpy_low(newcontext, scontext);
>> default:
>> - return -EINVAL;
>> + /* Fallthrough */
>> }
>> return -EINVAL;
>> }
>
> I don't think this compiles. GCC doesn't let you end a switch block
> with a label.
>
> I also have sent the selinux people a patch that didn't compile by
> mistake. Afterward I wrote this script so hopefully I won't mess up
> again.


Oops, sorry for this, my bad.
Thanks for your patch.

>
> #!/bin/bash -e
>
> files=$(grep +++ /home/dcarpenter/var/mail/postponed-msgs | cut -f 1 |
> cut -b 5-)
> for file in $files ; do
> file=${file/devel\//}
> file=${file/new\//}
> kchecker $file
> if which sparse | grep -q sparse ; then
> kchecker --sparse $file
> fi
> done
>
>
> You will have to change the path names. Hm.... Also you will have to
> get the kchecker script from the smatch_data/ directory of smatch
> (http://repo.or.cz/w/smatch.git).

Thanks for the info! I will have a try.

2009-12-08 09:52:45

by Cong Wang

[permalink] [raw]
Subject: Re: [Patch] selinux: remove a useless return

James Morris wrote:
> On Thu, 3 Dec 2009, Amerigo Wang wrote:
>
>> The last return is unreachable, remove the 'return'
>> in default, let it fall through.
>>
>> Signed-off-by: WANG Cong <[email protected]>
>> Cc: James Morris <[email protected]>
>> Cc: Eric Paris <[email protected]>
>
>
> Applied to
> git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/security-testing-2.6#next
>
> with a fixup for the problem reported by Dan Carpenter.
>
> You should not send out patches without testing them, even when following
> the advice of the person you're sending them to :-)
>

Right, will be careful, thank you!