Skip to content

Commit a1c4560

Browse files
error27airlied
authored andcommitted
drivers/gpu/drm/drm_sysfs.c: sysfs files error handling
In the original code we used "j" as an iterator but we used "i" as an index. - for (j = 0; j < i; j++) - device_remove_file(&connector->kdev, - &connector_attrs[i]); Smatch complained about that because "i" was potentially passed the end of the array. Which makes sense if we should be using "j" there. I also thought that we should remove the files for &connector_attrs_opt1 but to do that I had to add separate iterators for &connector_attrs and &connector_attrs_opt1. Signed-off-by: Dan Carpenter <error27@gmail.com> Cc: Greg Kroah-Hartman <gregkh@suse.de> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Dave Airlie <airlied@redhat.com>
1 parent 0031c41 commit a1c4560

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

drivers/gpu/drm/drm_sysfs.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,10 @@ static struct bin_attribute edid_attr = {
353353
int drm_sysfs_connector_add(struct drm_connector *connector)
354354
{
355355
struct drm_device *dev = connector->dev;
356-
int ret = 0, i, j;
356+
int attr_cnt = 0;
357+
int opt_cnt = 0;
358+
int i;
359+
int ret = 0;
357360

358361
/* We shouldn't get called more than once for the same connector */
359362
BUG_ON(device_is_registered(&connector->kdev));
@@ -376,8 +379,8 @@ int drm_sysfs_connector_add(struct drm_connector *connector)
376379

377380
/* Standard attributes */
378381

379-
for (i = 0; i < ARRAY_SIZE(connector_attrs); i++) {
380-
ret = device_create_file(&connector->kdev, &connector_attrs[i]);
382+
for (attr_cnt = 0; attr_cnt < ARRAY_SIZE(connector_attrs); attr_cnt++) {
383+
ret = device_create_file(&connector->kdev, &connector_attrs[attr_cnt]);
381384
if (ret)
382385
goto err_out_files;
383386
}
@@ -393,8 +396,8 @@ int drm_sysfs_connector_add(struct drm_connector *connector)
393396
case DRM_MODE_CONNECTOR_SVIDEO:
394397
case DRM_MODE_CONNECTOR_Component:
395398
case DRM_MODE_CONNECTOR_TV:
396-
for (i = 0; i < ARRAY_SIZE(connector_attrs_opt1); i++) {
397-
ret = device_create_file(&connector->kdev, &connector_attrs_opt1[i]);
399+
for (opt_cnt = 0; opt_cnt < ARRAY_SIZE(connector_attrs_opt1); opt_cnt++) {
400+
ret = device_create_file(&connector->kdev, &connector_attrs_opt1[opt_cnt]);
398401
if (ret)
399402
goto err_out_files;
400403
}
@@ -413,10 +416,10 @@ int drm_sysfs_connector_add(struct drm_connector *connector)
413416
return 0;
414417

415418
err_out_files:
416-
if (i > 0)
417-
for (j = 0; j < i; j++)
418-
device_remove_file(&connector->kdev,
419-
&connector_attrs[i]);
419+
for (i = 0; i < opt_cnt; i++)
420+
device_remove_file(&connector->kdev, &connector_attrs_opt1[i]);
421+
for (i = 0; i < attr_cnt; i++)
422+
device_remove_file(&connector->kdev, &connector_attrs[i]);
420423
device_unregister(&connector->kdev);
421424

422425
out:

0 commit comments

Comments
 (0)