From b55f8a1e4ce685003958789d805f61068477c472 Mon Sep 17 00:00:00 2001 From: Aditya Kumar Patra S Date: Mon, 6 Feb 2017 18:37:47 +0530 Subject: [PATCH] ipq806x: Detach ubi on ubi volume read error. Detach the ubi and the associated mtd device on error conditions. Change-Id: I7b1fc798b5e03e4b2a39370697a4615139273c15 Signed-off-by: Aditya Kumar Patra S --- common/cmd_ubi.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/common/cmd_ubi.c b/common/cmd_ubi.c index f7ebf020e2..394a169a4a 100644 --- a/common/cmd_ubi.c +++ b/common/cmd_ubi.c @@ -524,6 +524,7 @@ static int do_ubi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { int64_t size = 0; ulong addr = 0; + int err = 0; if (argc < 2) return CMD_RET_USAGE; @@ -661,7 +662,12 @@ static int do_ubi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) printf("Read %lld bytes from volume %s to %lx\n", size, argv[3], addr); - return ubi_volume_read(argv[3], (char *)addr, size); + err = ubi_volume_read(argv[3], (char *)addr, size); + if (err != 0) { + ubi_detach_mtd_dev(ubi_dev.nr, 1); + put_mtd_device(ubi_dev.mtd_info); + } + return err; } }