Skip to contentSkip to conversation

mtd: ubi: Test return value of __wl_get_peb

RFC/PATCH Applied Tanya Brokhman 4 participants 4 messages Apr 1, 2014 – Apr 8, 2014

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

In case of an error (if there are not free PEB's for example), __wl_get_peb will return a negative value. In order to prevent access violation we need to test the returned value prior to using it later on.

drivers/mtd/ubi/wl.c +3 -0
index 02317c1..457ead3 100644
@@ -684,6 +684,9 @@ int ubi_wl_get_peb(struct ubi_device *ubi)
 	peb = __wl_get_peb(ubi);
 	spin_unlock(&ubi->wl_lock);
 
+	if (peb < 0)
+		return peb;
+
 	err = ubi_self_check_all_ff(ubi, peb, ubi->vid_hdr_aloffset,
 				    ubi->peb_size - ubi->vid_hdr_aloffset);
 	if (err) {
Signature · 4 lines
1.7.6
-- 
QUALCOMM ISRAEL, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation
Reviewed-by
#1 lore raw

Thanks,
Dolev

Signature · 2 lines
QUALCOMM ISRAEL, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation

-----Original Message-----
From: linux-mtd [mailto:[email protected]] On Behalf Of Tanya Brokhman
Sent: Tuesday, April 01, 2014 11:01 AM
To: [email protected]
Cc: [email protected]; open list; Tanya Brokhman
Subject: [RFC/PATCH] mtd: ubi: Test return value of __wl_get_peb

In case of an error (if there are not free PEB's for example), __wl_get_peb will return a negative value. In order to prevent access violation we need to test the returned value prior to using it later on.

drivers/mtd/ubi/wl.c index renamed from drivers/mtd/ubi/wl.c +0 -0

02317c1..457ead3 100644

drivers/mtd/ubi/wl.c +3 -0
@@ -684,6 +684,9 @@ int ubi_wl_get_peb(struct ubi_device *ubi)
 	peb = __wl_get_peb(ubi);
 	spin_unlock(&ubi->wl_lock);
 
+	if (peb < 0)
+		return peb;
+
 	err = ubi_self_check_all_ff(ubi, peb, ubi->vid_hdr_aloffset,
 				    ubi->peb_size - ubi->vid_hdr_aloffset);
 	if (err) {

--
1.7.6
--
QUALCOMM ISRAEL, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

#2 lore raw
In reply to Tanya Brokhman
Quoted 11 lines · Tanya Brokhman

In case of an error (if there are not free PEB's for example), __wl_get_peb will return a negative value. In order to prevent access violation we need to test the returned value prior to using it later on.

drivers/mtd/ubi/wl.c +0 -0
index 02317c1..457ead3 100644

drivers/mtd/ubi/wl.c int ubi_wl_get_peb(struct ubi_device *ubi) · line 692

Quoted 9 lines
drivers/mtd/ubi/wl.c +3 -0
@@ -684,6 +684,9 @@ int ubi_wl_get_peb(struct ubi_device *ubi)
        peb = __wl_get_peb(ubi);
        spin_unlock(&ubi->wl_lock);
 
+       if (peb < 0)
+               return peb;
+
        err = ubi_self_check_all_ff(ubi, peb, ubi->vid_hdr_aloffset,
                                    ubi->peb_size - ubi->vid_hdr_aloffset);
        if (err) {
Signature · 2 lines
Thanks,
//richard
#3 lore raw
In reply to Tanya Brokhman
Quoted 5 lines · Tanya Brokhman

In case of an error (if there are not free PEB's for example), __wl_get_peb will return a negative value. In order to prevent access violation we need to test the returned value prior to using it later on.

Pushed to linux-ubifs.git / master, thanks!

Signature · 2 lines
Best Regards,
Artem Bityutskiy