Skip to contentSkip to conversation

mtdblock read sector and cache_data == NULL

DISCUSSION Cestonaro Thilo 1 participant 2 messages Feb 11, 2014 1 message not in the archive SPI

lore
Share & tools
lore
#0 lore raw

Hey,

I think the cache_data buffer is used uninitialized in case no write prepends the first read.

Initialization of cache_data buffer:
https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/drivers/mtd/mtdblock.c?id=refs/tags/v3.14-rc2#n300
--------------------

    if (!(mbd->mtd->flags & MTD_NO_ERASE) && mbd->mtd->erasesize) {
        mtdblk->cache_size = mbd->mtd->erasesize;
        mtdblk->cache_data = NULL;
    }

----------------

And later in do_cached_read it is just used with mtdblock->cache_data + offset.
https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/drivers/mtd/mtdblock.c?id=refs/tags/v3.14-rc2#n243

The only allocation I can find is in writesector function, so I figured that the mtd_read will get NULL+offset in the first read.
https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/drivers/mtd/mtdblock.c?id=refs/tags/v3.14-rc2#n272

Is it correct to place the same if unlikely stuff in the mtdblock_readsect function like in the mtdblock_writesect one?

Greetings
Thilo

--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#2 lore raw
In reply to a message not in the archive

hey,

forget it :) ... I got confused ....

Greetings Thilo

Quoted 29 lines · Cestonaro Thilo

Hey,

I think the cache_data buffer is used uninitialized in case no write prepends the first read.

Initialization of cache_data buffer:
https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/drivers/mtd/mtdblock.c?id=refs/tags/v3.14-rc2#n300
--------------------

    if (!(mbd->mtd->flags & MTD_NO_ERASE) && mbd->mtd->erasesize) {
        mtdblk->cache_size = mbd->mtd->erasesize;
        mtdblk->cache_data = NULL;
    }

----------------

And later in do_cached_read it is just used with mtdblock->cache_data + offset.
https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/drivers/mtd/mtdblock.c?id=refs/tags/v3.14-rc2#n243

The only allocation I can find is in writesector function, so I figured that the mtd_read will get NULL+offset in the first read.
https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/drivers/mtd/mtdblock.c?id=refs/tags/v3.14-rc2#n272

Is it correct to place the same if unlikely stuff in the mtdblock_readsect function like in the mtdblock_writesect one?

Greetings
Thilo

Signature · 21 lines
With best regards
Thilo Cestonaro

FTS PBG PDG WPS R&D EPC

Fujitsu Technology Solutions GmbH
Buergermeister-Ulrich-Str. 100
86199 Augsburg
Germany

Tel.: +49 (0)821 804 2328
Fax: +49 (0)821 804 82328
E-mail: [email protected]

Web: http://ts.fujitsu.com
Company details: http://ts.fujitsu.com/imprint

--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html