Message ID | 1574703927-19823-1-git-send-email-philippe.reynes@softathome.com |
---|---|
State | Accepted |
Headers | show |
Series | uboot_env: fix the resarch of ubi volume | expand |
On 25/11/19 18:45, Philippe Reynes wrote: > In the function ubi_get_vol_id, when we search the volume id > with the volume name, we try all id from 0 to num_volume. But > the volume id may be greater than the actual number of volume. > To avoid this issue, we try all the id from 0 to 128 (max ubi > volume id). > > Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com> > --- > src/uboot_env.c | 12 ++++++++++-- > 1 file changed, 10 insertions(+), 2 deletions(-) > > diff --git a/src/uboot_env.c b/src/uboot_env.c > index b59b140..0f33931 100644 > --- a/src/uboot_env.c > +++ b/src/uboot_env.c > @@ -36,6 +36,8 @@ > > #include "uboot_private.h" > > +#define UBI_MAX_VOLUME 128 > + > #define DEVICE_MTD_NAME "/dev/mtd" > #define DEVICE_UBI_NAME "/dev/ubi" > #define SYS_UBI_VOLUME_COUNT "/sys/class/ubi/ubi%d/volumes_count" > @@ -230,13 +232,15 @@ out: > > static int ubi_get_vol_id(char *device, char *volname) > { > - int i, ret, num_vol, vol_id = -1; > + int i, n, ret, num_vol, vol_id = -1; > > num_vol = ubi_get_num_volume(device); > if (num_vol < 0) > goto out; > > - for (i=0; i<num_vol; i++) > + i = 0; > + n = 0; > + while ((n < num_vol) && (i < UBI_MAX_VOLUME)) > { > char name[DEVNAME_MAX_LENGTH]; > > @@ -245,6 +249,10 @@ static int ubi_get_vol_id(char *device, char *volname) > vol_id = i; > break; > } > + > + i++; > + if (!ret) > + n++; > } > > out: > Applied to -master, thanks ! Best regards, Stefano Babic
diff --git a/src/uboot_env.c b/src/uboot_env.c index b59b140..0f33931 100644 --- a/src/uboot_env.c +++ b/src/uboot_env.c @@ -36,6 +36,8 @@ #include "uboot_private.h" +#define UBI_MAX_VOLUME 128 + #define DEVICE_MTD_NAME "/dev/mtd" #define DEVICE_UBI_NAME "/dev/ubi" #define SYS_UBI_VOLUME_COUNT "/sys/class/ubi/ubi%d/volumes_count" @@ -230,13 +232,15 @@ out: static int ubi_get_vol_id(char *device, char *volname) { - int i, ret, num_vol, vol_id = -1; + int i, n, ret, num_vol, vol_id = -1; num_vol = ubi_get_num_volume(device); if (num_vol < 0) goto out; - for (i=0; i<num_vol; i++) + i = 0; + n = 0; + while ((n < num_vol) && (i < UBI_MAX_VOLUME)) { char name[DEVNAME_MAX_LENGTH]; @@ -245,6 +249,10 @@ static int ubi_get_vol_id(char *device, char *volname) vol_id = i; break; } + + i++; + if (!ret) + n++; } out:
In the function ubi_get_vol_id, when we search the volume id with the volume name, we try all id from 0 to num_volume. But the volume id may be greater than the actual number of volume. To avoid this issue, we try all the id from 0 to 128 (max ubi volume id). Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com> --- src/uboot_env.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)