[PATCH v3] mtd: Fix the behavior of OTP write if there is not enough room for data

Brian Norris computersforpeace at gmail.com
Sat Mar 8 23:56:15 EST 2014


On Thu, Mar 06, 2014 at 12:42:37PM +0100, Christian Riesch wrote:
> If a write to one time programmable memory (OTP) hits the end of this
> memory area, no more data can be written. The count variable in
> mtdchar_write() in drivers/mtd/mtdchar.c is not decreased anymore.
> We are trapped in the loop forever, mtdchar_write() will never return
> in this case.
> 
> The desired behavior of a write in such a case is described in [1]:
> - Try to write as much data as possible, truncate the write to fit into
>   the available memory and return the number of bytes that actually
>   have been written.
> - If no data could be written at all, return -ENOSPC.
> 
> This patch fixes the behavior of OTP write if there is not enough space
> for all data:
> 
> 1) mtd_write_user_prot_reg() in drivers/mtd/mtdcore.c is modified to
>    return -ENOSPC if no data could be written at all.
> 2) mtdchar_write() is modified to handle -ENOSPC correctly. Exit if a
>    write returned -ENOSPC and yield the correct return value, either
>    then number of bytes that could be written, or -ENOSPC, if no data
>    could be written at all.
> 
> Furthermore the patch harmonizes the behavior of the OTP memory write
> in drivers/mtd/devices/mtd_dataflash.c with the other implementations
> and the requirements from [1]. Instead of returning -EINVAL if the data
> does not fit into the OTP memory, we try to write as much data as
> possible/truncate the write.
> 
> [1] http://pubs.opengroup.org/onlinepubs/9699919799/functions/write.html
> 
> Signed-off-by: Christian Riesch <christian.riesch at omicron.at>
> Cc: Brian Norris <computersforpeace at gmail.com>
> ---
> 
> Changes for v3:
> - Moved logic for returning -ENOSPC from cfi_intelext_write_user_prot_reg,
>   dataflash_write_user_otp, onenand_write_user_prot_reg to a common
>   implementation in mtd_write_user_prot_reg, as requested by Brian Norris.
> - Simplified the code in mtdchar_write as suggested by Brian.
> - Added more comments, commit message.

Thanks for the update. Pushed to l2-mtd.git!

Brian



More information about the linux-mtd mailing list