If 0 is passed to the 'bytes' parameter in the ubi_start_update(),
there is no need to call the ubi_more_update_data(). Otherwise,
there will be a double-free of 'vol->upd_buf'.
Also check that the ubi_start_update() was called before calling
the ubi_more_update_data().
Signed-off-by: Martin Kurbanov <mmkurbanov@salutedevices.com>
if (vol == NULL)
return ENODEV;
+ if (!vol->updating) {
+ printf("UBI volume update was not initiated\n");
+ return EINVAL;
+ }
+
err = ubi_more_update_data(ubi, vol, buf, size);
if (err < 0) {
printf("Couldnt or partially wrote data\n");
return -err;
}
+ /* The volume is just wiped out */
+ if (!full_size)
+ return 0;
+
return ubi_volume_continue_write(volume, buf, size);
}