aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd/sm_ftl.c
diff options
context:
space:
mode:
authorXiaochen Wang <wangxiaochen0@gmail.com>2011-03-10 09:31:39 -0500
committerDavid Woodhouse <David.Woodhouse@intel.com>2011-03-11 09:27:10 -0500
commit629286b9561982e90a6d49893a1c641e71b6a2a3 (patch)
treecb32198537f69897e2640724972db9bb52c574d8 /drivers/mtd/sm_ftl.c
parent1065cda8a1a57d0d3bfccdce1a655a84439d24e0 (diff)
mtd: sm_rtl: check kmalloc return value
Because malloc/kzalloc may fail, we should check kmalloc/kzalloc return value in sm_create_sysfs_attributes(), mtd/sm_rtl.c and do error handling. Meanwhile, we should check sm_create_sysfs_attributes return value. Signed-off-by: Xiaochen Wang <wangxiaochen0@gmail.com> Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com> Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Diffstat (limited to 'drivers/mtd/sm_ftl.c')
-rw-r--r--drivers/mtd/sm_ftl.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
index 67822cf6c025..6405a95dc5bd 100644
--- a/drivers/mtd/sm_ftl.c
+++ b/drivers/mtd/sm_ftl.c
@@ -64,12 +64,16 @@ struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
64 SM_SMALL_PAGE - SM_CIS_VENDOR_OFFSET); 64 SM_SMALL_PAGE - SM_CIS_VENDOR_OFFSET);
65 65
66 char *vendor = kmalloc(vendor_len, GFP_KERNEL); 66 char *vendor = kmalloc(vendor_len, GFP_KERNEL);
67 if (!vendor)
68 goto error1;
67 memcpy(vendor, ftl->cis_buffer + SM_CIS_VENDOR_OFFSET, vendor_len); 69 memcpy(vendor, ftl->cis_buffer + SM_CIS_VENDOR_OFFSET, vendor_len);
68 vendor[vendor_len] = 0; 70 vendor[vendor_len] = 0;
69 71
70 /* Initialize sysfs attributes */ 72 /* Initialize sysfs attributes */
71 vendor_attribute = 73 vendor_attribute =
72 kzalloc(sizeof(struct sm_sysfs_attribute), GFP_KERNEL); 74 kzalloc(sizeof(struct sm_sysfs_attribute), GFP_KERNEL);
75 if (!vendor_attribute)
76 goto error2;
73 77
74 sysfs_attr_init(&vendor_attribute->dev_attr.attr); 78 sysfs_attr_init(&vendor_attribute->dev_attr.attr);
75 79
@@ -83,12 +87,24 @@ struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
83 /* Create array of pointers to the attributes */ 87 /* Create array of pointers to the attributes */
84 attributes = kzalloc(sizeof(struct attribute *) * (NUM_ATTRIBUTES + 1), 88 attributes = kzalloc(sizeof(struct attribute *) * (NUM_ATTRIBUTES + 1),
85 GFP_KERNEL); 89 GFP_KERNEL);
90 if (!attributes)
91 goto error3;
86 attributes[0] = &vendor_attribute->dev_attr.attr; 92 attributes[0] = &vendor_attribute->dev_attr.attr;
87 93
88 /* Finally create the attribute group */ 94 /* Finally create the attribute group */
89 attr_group = kzalloc(sizeof(struct attribute_group), GFP_KERNEL); 95 attr_group = kzalloc(sizeof(struct attribute_group), GFP_KERNEL);
96 if (!attr_group)
97 goto error4;
90 attr_group->attrs = attributes; 98 attr_group->attrs = attributes;
91 return attr_group; 99 return attr_group;
100error4:
101 kfree(attributes);
102error3:
103 kfree(vendor_attribute);
104error2:
105 kfree(vendor);
106error1:
107 return NULL;
92} 108}
93 109
94void sm_delete_sysfs_attributes(struct sm_ftl *ftl) 110void sm_delete_sysfs_attributes(struct sm_ftl *ftl)
@@ -1178,6 +1194,8 @@ static void sm_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
1178 } 1194 }
1179 1195
1180 ftl->disk_attributes = sm_create_sysfs_attributes(ftl); 1196 ftl->disk_attributes = sm_create_sysfs_attributes(ftl);
1197 if (!ftl->disk_attributes)
1198 goto error6;
1181 trans->disk_attributes = ftl->disk_attributes; 1199 trans->disk_attributes = ftl->disk_attributes;
1182 1200
1183 sm_printk("Found %d MiB xD/SmartMedia FTL on mtd%d", 1201 sm_printk("Found %d MiB xD/SmartMedia FTL on mtd%d",