Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

extcon: Add extcon_alloc_groups to simplify extcon register function

The alloc groups is functionalized from extcon_dev_register.

Signed-off-by: Bumwoo Lee <bw365.lee@samsung.com>
Acked-by: MyungJoo Ham <myungjoo.ham@samsung.com
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>

authored by

Bumwoo Lee and committed by
Chanwoo Choi
04151575 3e70a014

+39 -22
+39 -22
drivers/extcon/extcon.c
··· 1188 1188 } 1189 1189 1190 1190 /** 1191 + * extcon_alloc_groups() - alloc the groups for extcon device 1192 + * @edev: extcon device 1193 + * 1194 + * Returns 0 if success or error number if fail. 1195 + */ 1196 + static int extcon_alloc_groups(struct extcon_dev *edev) 1197 + { 1198 + int index; 1199 + 1200 + if (!edev) 1201 + return -EINVAL; 1202 + 1203 + if (!edev->max_supported) 1204 + return 0; 1205 + 1206 + edev->extcon_dev_type.groups = kcalloc(edev->max_supported + 2, 1207 + sizeof(struct attribute_group *), 1208 + GFP_KERNEL); 1209 + if (!edev->extcon_dev_type.groups) 1210 + return -ENOMEM; 1211 + 1212 + edev->extcon_dev_type.name = dev_name(&edev->dev); 1213 + edev->extcon_dev_type.release = dummy_sysfs_dev_release; 1214 + 1215 + for (index = 0; index < edev->max_supported; index++) 1216 + edev->extcon_dev_type.groups[index] = &edev->cables[index].attr_g; 1217 + 1218 + if (edev->mutually_exclusive) 1219 + edev->extcon_dev_type.groups[index] = &edev->attr_g_muex; 1220 + 1221 + edev->dev.type = &edev->extcon_dev_type; 1222 + 1223 + return 0; 1224 + } 1225 + 1226 + /** 1191 1227 * extcon_dev_register() - Register an new extcon device 1192 1228 * @edev: the extcon device to be registered 1193 1229 * ··· 1278 1242 if (ret < 0) 1279 1243 goto err_alloc_muex; 1280 1244 1281 - if (edev->max_supported) { 1282 - edev->extcon_dev_type.groups = 1283 - kcalloc(edev->max_supported + 2, 1284 - sizeof(struct attribute_group *), 1285 - GFP_KERNEL); 1286 - if (!edev->extcon_dev_type.groups) { 1287 - ret = -ENOMEM; 1288 - goto err_alloc_groups; 1289 - } 1290 - 1291 - edev->extcon_dev_type.name = dev_name(&edev->dev); 1292 - edev->extcon_dev_type.release = dummy_sysfs_dev_release; 1293 - 1294 - for (index = 0; index < edev->max_supported; index++) 1295 - edev->extcon_dev_type.groups[index] = 1296 - &edev->cables[index].attr_g; 1297 - if (edev->mutually_exclusive) 1298 - edev->extcon_dev_type.groups[index] = 1299 - &edev->attr_g_muex; 1300 - 1301 - edev->dev.type = &edev->extcon_dev_type; 1302 - } 1245 + ret = extcon_alloc_groups(edev); 1246 + if (ret < 0) 1247 + goto err_alloc_groups; 1303 1248 1304 1249 spin_lock_init(&edev->lock); 1305 1250 if (edev->max_supported) {