Patchwork [v3,3/6] UBI: check max_beb_per1024 value in ubi_attach_mtd_dev

login
register
mail settings
Submitter Richard Genoud
Date Aug. 20, 2012, 4 p.m.
Message ID <1345478416-23900-4-git-send-email-richard.genoud@gmail.com>
Download mbox | patch
Permalink /patch/178866/
State New
Headers show

Comments

Richard Genoud - Aug. 20, 2012, 4 p.m.
max_beb_per1024 shouldn't be negative, and a 0 value will be treated as
the default value.
For the upper bound, 768/1024 should be enough.

Signed-off-by: Richard Genoud <richard.genoud@gmail.com>
---
 drivers/mtd/ubi/build.c |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)
Artem Bityutskiy - Aug. 20, 2012, 7:19 p.m.
On Mon, 2012-08-20 at 18:00 +0200, Richard Genoud wrote:
> @@ -855,6 +858,15 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num,
>  	struct ubi_device *ubi;
>  	int i, err, ref = 0;
>  
> +	if ((max_beb_per1024 < 0) || (max_beb_per1024 > MAX_MTD_UBI_BEB_LIMIT))
> +		return -EINVAL;

Removed excessive brackets and pushed to linux-ubi, thanks!

Patch

diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
index 3c0b91f..6a749d6 100644
--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
@@ -49,6 +49,9 @@ 
 /* Maximum number of comma-separated items in the 'mtd=' parameter */
 #define MTD_PARAM_MAX_COUNT 2
 
+/* Maximum value for the number of bad eraseblocks per 1024 limit */
+#define MAX_MTD_UBI_BEB_LIMIT 768
+
 #ifdef CONFIG_MTD_UBI_MODULE
 #define ubi_is_module() 1
 #else
@@ -855,6 +858,15 @@  int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num,
 	struct ubi_device *ubi;
 	int i, err, ref = 0;
 
+	if ((max_beb_per1024 < 0) || (max_beb_per1024 > MAX_MTD_UBI_BEB_LIMIT))
+		return -EINVAL;
+
+	/*
+	 * Use the default value if max_beb_per1024 isn't provided.
+	 */
+	if (!max_beb_per1024)
+		max_beb_per1024 = CONFIG_MTD_UBI_BEB_LIMIT;
+
 	/*
 	 * Check if we already have the same MTD device attached.
 	 *