From: Michael Ellerman <mpe@ellerman.id.au>
To: christophe leroy <christophe.leroy@c-s.fr>,
Dan Carpenter <dan.carpenter@oracle.com>,
Geoff Levand <geoff@infradead.org>,
Geert Uytterhoeven <Geert.Uytterhoeven@sonycom.com>
Cc: kernel-janitors@vger.kernel.org,
Paul Mackerras <paulus@samba.org>,
linuxppc-dev@lists.ozlabs.org
Subject: Re: [PATCH] powerpc: signedness bug in update_flash_db()
Date: Tue, 09 Oct 2018 11:54:27 +0000 [thread overview]
Message-ID: <87in2b1gjw.fsf@concordia.ellerman.id.au> (raw)
In-Reply-To: <6fa5827e-3346-4057-ca44-c6d9758f5837@c-s.fr>
christophe leroy <christophe.leroy@c-s.fr> writes:
> Le 01/10/2018 à 18:44, Dan Carpenter a écrit :
>> The "count < sizeof(struct os_area_db)" comparison is type promoted to
>> size_t so negative values of "count" are treated as very high values and
>> we accidentally return success instead of a negative error code.
>>
>> This doesn't really change runtime much but it fixes a static checker
>> warning.
>>
>> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
>>
>> diff --git a/arch/powerpc/platforms/ps3/os-area.c b/arch/powerpc/platforms/ps3/os-area.c
>> index cdbfc5cfd6f3..f5387ad82279 100644
>> --- a/arch/powerpc/platforms/ps3/os-area.c
>> +++ b/arch/powerpc/platforms/ps3/os-area.c
>> @@ -664,7 +664,7 @@ static int update_flash_db(void)
>> db_set_64(db, &os_area_db_id_rtc_diff, saved_params.rtc_diff);
>>
>> count = os_area_flash_write(db, sizeof(struct os_area_db), pos);
>> - if (count < sizeof(struct os_area_db)) {
>> + if (count < 0 || count < sizeof(struct os_area_db)) {
>
> Why not simply add a cast ? :
>
> if (count < (ssize_t)sizeof(struct os_area_db)) {
The explicit check against 0 is much clearer IMO.
The original author and all reviewers since obviously didn't realise
that count was being implicitly cast, so fixing that with another cast
seems likely to just confuse people even more :)
cheers
next prev parent reply other threads:[~2018-10-09 11:54 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-01 16:44 [PATCH] powerpc: signedness bug in update_flash_db() Dan Carpenter
2018-10-01 18:22 ` christophe leroy
2018-10-01 19:02 ` Dan Carpenter
2018-10-01 19:06 ` Dan Carpenter
2018-10-09 11:54 ` Michael Ellerman [this message]
2018-10-01 22:45 ` Geoff Levand
2018-10-15 4:01 ` Michael Ellerman
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=87in2b1gjw.fsf@concordia.ellerman.id.au \
--to=mpe@ellerman.id.au \
--cc=Geert.Uytterhoeven@sonycom.com \
--cc=christophe.leroy@c-s.fr \
--cc=dan.carpenter@oracle.com \
--cc=geoff@infradead.org \
--cc=kernel-janitors@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=paulus@samba.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox