mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: Sascha Hauer <s.hauer@pengutronix.de>,
	Antony Pavlov <antonynpavlov@gmail.com>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH 1/2] mtd: core: fix use of uninitialized struct member
Date: Fri, 11 Jun 2021 12:42:58 +0200	[thread overview]
Message-ID: <a0eda784-966d-b919-4342-f29ba1133d1b@pengutronix.de> (raw)
In-Reply-To: <20210611102356.GE22904@pengutronix.de>

On 11.06.21 12:23, Sascha Hauer wrote:
> Hi Antony,
> 
> On Fri, Jun 11, 2021 at 09:39:13AM +0300, Antony Pavlov wrote:
>> E.g. mtd_read() calls mtd_read_oob(), mtd_read_oob()
>> can check uninitialized ops->oobbuf. As a result
>> mtd_read_oob() can return -EOPNOTSUPP.
>>
>> Found on a MIPS board during /dev/m25p0 read, e.g.
>>
>>   barebox:/ md -s /dev/m25p0
>>   read: error 95
>>
>> Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
>> ---
>>  drivers/mtd/core.c | 18 ++++++++++--------
>>  1 file changed, 10 insertions(+), 8 deletions(-)
>>
>> diff --git a/drivers/mtd/core.c b/drivers/mtd/core.c
>> index 37fccda6be..98820dfb4f 100644
>> --- a/drivers/mtd/core.c
>> +++ b/drivers/mtd/core.c
>> @@ -379,12 +379,13 @@ int mtd_block_markgood(struct mtd_info *mtd, loff_t ofs)
>>  int mtd_read(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen,
>>               u_char *buf)
>>  {
>> -	struct mtd_oob_ops ops = {
>> -		.len = len,
>> -		.datbuf = buf,
>> -	};
>> +	struct mtd_oob_ops ops;
>>  	int ret;
>>  
>> +	memset(&ops, 0, sizeof(ops));
>> +	ops.len = len;
>> +	ops.datbuf = buf;
> 
> If this fixes something for you then you have severe problems with your
> compiler. Omitted fields are implicitly initialized to zero, often you
> can even find the corresponding call to memset in the objdump.

Perhaps elsewhere something is interpreting the padding, which may
not be zeroed when using an initializer list. This warrants further investigation
for sure.

Cheers,
Ahmad


-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


  reply	other threads:[~2021-06-11 10:44 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-11  6:39 [PATCH 0/2] " Antony Pavlov
2021-06-11  6:39 ` [PATCH 1/2] " Antony Pavlov
2021-06-11 10:23   ` Sascha Hauer
2021-06-11 10:42     ` Ahmad Fatoum [this message]
2021-06-11  6:39 ` [PATCH 2/2] mtd: core: fix whitespaces Antony Pavlov

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=a0eda784-966d-b919-4342-f29ba1133d1b@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=antonynpavlov@gmail.com \
    --cc=barebox@lists.infradead.org \
    --cc=s.hauer@pengutronix.de \
    /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