Commit 629286b9561982e90a6d49893a1c641e71b6a2a3
Committed by
David Woodhouse
1 parent
1065cda8a1
Exists in
master
and in
7 other branches
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>
Showing 1 changed file with 18 additions and 0 deletions Side-by-side Diff
drivers/mtd/sm_ftl.c
... | ... | @@ -64,12 +64,16 @@ |
64 | 64 | SM_SMALL_PAGE - SM_CIS_VENDOR_OFFSET); |
65 | 65 | |
66 | 66 | char *vendor = kmalloc(vendor_len, GFP_KERNEL); |
67 | + if (!vendor) | |
68 | + goto error1; | |
67 | 69 | memcpy(vendor, ftl->cis_buffer + SM_CIS_VENDOR_OFFSET, vendor_len); |
68 | 70 | vendor[vendor_len] = 0; |
69 | 71 | |
70 | 72 | /* Initialize sysfs attributes */ |
71 | 73 | vendor_attribute = |
72 | 74 | kzalloc(sizeof(struct sm_sysfs_attribute), GFP_KERNEL); |
75 | + if (!vendor_attribute) | |
76 | + goto error2; | |
73 | 77 | |
74 | 78 | sysfs_attr_init(&vendor_attribute->dev_attr.attr); |
75 | 79 | |
76 | 80 | |
77 | 81 | |
... | ... | @@ -83,12 +87,24 @@ |
83 | 87 | /* Create array of pointers to the attributes */ |
84 | 88 | attributes = kzalloc(sizeof(struct attribute *) * (NUM_ATTRIBUTES + 1), |
85 | 89 | GFP_KERNEL); |
90 | + if (!attributes) | |
91 | + goto error3; | |
86 | 92 | attributes[0] = &vendor_attribute->dev_attr.attr; |
87 | 93 | |
88 | 94 | /* Finally create the attribute group */ |
89 | 95 | attr_group = kzalloc(sizeof(struct attribute_group), GFP_KERNEL); |
96 | + if (!attr_group) | |
97 | + goto error4; | |
90 | 98 | attr_group->attrs = attributes; |
91 | 99 | return attr_group; |
100 | +error4: | |
101 | + kfree(attributes); | |
102 | +error3: | |
103 | + kfree(vendor_attribute); | |
104 | +error2: | |
105 | + kfree(vendor); | |
106 | +error1: | |
107 | + return NULL; | |
92 | 108 | } |
93 | 109 | |
94 | 110 | void sm_delete_sysfs_attributes(struct sm_ftl *ftl) |
... | ... | @@ -1178,6 +1194,8 @@ |
1178 | 1194 | } |
1179 | 1195 | |
1180 | 1196 | ftl->disk_attributes = sm_create_sysfs_attributes(ftl); |
1197 | + if (!ftl->disk_attributes) | |
1198 | + goto error6; | |
1181 | 1199 | trans->disk_attributes = ftl->disk_attributes; |
1182 | 1200 | |
1183 | 1201 | sm_printk("Found %d MiB xD/SmartMedia FTL on mtd%d", |