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_muex to simplify extcon register function

The mutual exclusive part 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
3e70a014 3d9138e5

+61 -48
+61 -48
drivers/extcon/extcon.c
··· 1131 1131 } 1132 1132 1133 1133 /** 1134 + * extcon_alloc_muex() - alloc the mutual exclusive for extcon device 1135 + * @edev: extcon device 1136 + * 1137 + * Returns 0 if success or error number if fail. 1138 + */ 1139 + static int extcon_alloc_muex(struct extcon_dev *edev) 1140 + { 1141 + char *name; 1142 + int index; 1143 + 1144 + if (!edev) 1145 + return -EINVAL; 1146 + 1147 + if (!(edev->max_supported && edev->mutually_exclusive)) 1148 + return 0; 1149 + 1150 + /* Count the size of mutually_exclusive array */ 1151 + for (index = 0; edev->mutually_exclusive[index]; index++) 1152 + ; 1153 + 1154 + edev->attrs_muex = kcalloc(index + 1, 1155 + sizeof(struct attribute *), 1156 + GFP_KERNEL); 1157 + if (!edev->attrs_muex) 1158 + return -ENOMEM; 1159 + 1160 + edev->d_attrs_muex = kcalloc(index, 1161 + sizeof(struct device_attribute), 1162 + GFP_KERNEL); 1163 + if (!edev->d_attrs_muex) { 1164 + kfree(edev->attrs_muex); 1165 + return -ENOMEM; 1166 + } 1167 + 1168 + for (index = 0; edev->mutually_exclusive[index]; index++) { 1169 + name = kasprintf(GFP_KERNEL, "0x%x", 1170 + edev->mutually_exclusive[index]); 1171 + if (!name) { 1172 + for (index--; index >= 0; index--) 1173 + kfree(edev->d_attrs_muex[index].attr.name); 1174 + 1175 + kfree(edev->d_attrs_muex); 1176 + kfree(edev->attrs_muex); 1177 + return -ENOMEM; 1178 + } 1179 + sysfs_attr_init(&edev->d_attrs_muex[index].attr); 1180 + edev->d_attrs_muex[index].attr.name = name; 1181 + edev->d_attrs_muex[index].attr.mode = 0000; 1182 + edev->attrs_muex[index] = &edev->d_attrs_muex[index].attr; 1183 + } 1184 + edev->attr_g_muex.name = muex_name; 1185 + edev->attr_g_muex.attrs = edev->attrs_muex; 1186 + 1187 + return 0; 1188 + } 1189 + 1190 + /** 1134 1191 * extcon_dev_register() - Register an new extcon device 1135 1192 * @edev: the extcon device to be registered 1136 1193 * ··· 1238 1181 if (ret < 0) 1239 1182 goto err_alloc_cables; 1240 1183 1241 - if (edev->max_supported && edev->mutually_exclusive) { 1242 - char *name; 1243 - 1244 - /* Count the size of mutually_exclusive array */ 1245 - for (index = 0; edev->mutually_exclusive[index]; index++) 1246 - ; 1247 - 1248 - edev->attrs_muex = kcalloc(index + 1, 1249 - sizeof(struct attribute *), 1250 - GFP_KERNEL); 1251 - if (!edev->attrs_muex) { 1252 - ret = -ENOMEM; 1253 - goto err_muex; 1254 - } 1255 - 1256 - edev->d_attrs_muex = kcalloc(index, 1257 - sizeof(struct device_attribute), 1258 - GFP_KERNEL); 1259 - if (!edev->d_attrs_muex) { 1260 - ret = -ENOMEM; 1261 - kfree(edev->attrs_muex); 1262 - goto err_muex; 1263 - } 1264 - 1265 - for (index = 0; edev->mutually_exclusive[index]; index++) { 1266 - name = kasprintf(GFP_KERNEL, "0x%x", 1267 - edev->mutually_exclusive[index]); 1268 - if (!name) { 1269 - for (index--; index >= 0; index--) { 1270 - kfree(edev->d_attrs_muex[index].attr. 1271 - name); 1272 - } 1273 - kfree(edev->d_attrs_muex); 1274 - kfree(edev->attrs_muex); 1275 - ret = -ENOMEM; 1276 - goto err_muex; 1277 - } 1278 - sysfs_attr_init(&edev->d_attrs_muex[index].attr); 1279 - edev->d_attrs_muex[index].attr.name = name; 1280 - edev->d_attrs_muex[index].attr.mode = 0000; 1281 - edev->attrs_muex[index] = &edev->d_attrs_muex[index] 1282 - .attr; 1283 - } 1284 - edev->attr_g_muex.name = muex_name; 1285 - edev->attr_g_muex.attrs = edev->attrs_muex; 1286 - 1287 - } 1184 + ret = extcon_alloc_muex(edev); 1185 + if (ret < 0) 1186 + goto err_alloc_muex; 1288 1187 1289 1188 if (edev->max_supported) { 1290 1189 edev->extcon_dev_type.groups = ··· 1308 1295 kfree(edev->d_attrs_muex); 1309 1296 kfree(edev->attrs_muex); 1310 1297 } 1311 - err_muex: 1298 + err_alloc_muex: 1312 1299 for (index = 0; index < edev->max_supported; index++) 1313 1300 kfree(edev->cables[index].attr_g.name); 1314 1301 if (edev->max_supported)