aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorDan Carpenter <error27@gmail.com>2010-04-27 17:11:05 -0400
committerDave Airlie <airlied@redhat.com>2010-04-28 04:42:52 -0400
commita1c4560d4d8909cc4feb6f9e875d0b92083e05cf (patch)
tree5fad4d68b80048f95068637c17888d700a47e09e /drivers
parent0031c41be5c529f8329e327b63cde92ba1284842 (diff)
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>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/gpu/drm/drm_sysfs.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c
index 014ce24761b9..f144487aa5b1 100644
--- a/drivers/gpu/drm/drm_sysfs.c
+++ b/drivers/gpu/drm/drm_sysfs.c
@@ -353,7 +353,10 @@ static struct bin_attribute edid_attr = {
353int drm_sysfs_connector_add(struct drm_connector *connector) 353int drm_sysfs_connector_add(struct drm_connector *connector)
354{ 354{
355 struct drm_device *dev = connector->dev; 355 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;
357 360
358 /* We shouldn't get called more than once for the same connector */ 361 /* We shouldn't get called more than once for the same connector */
359 BUG_ON(device_is_registered(&connector->kdev)); 362 BUG_ON(device_is_registered(&connector->kdev));
@@ -376,8 +379,8 @@ int drm_sysfs_connector_add(struct drm_connector *connector)
376 379
377 /* Standard attributes */ 380 /* Standard attributes */
378 381
379 for (i = 0; i < ARRAY_SIZE(connector_attrs); i++) { 382 for (attr_cnt = 0; attr_cnt < ARRAY_SIZE(connector_attrs); attr_cnt++) {
380 ret = device_create_file(&connector->kdev, &connector_attrs[i]); 383 ret = device_create_file(&connector->kdev, &connector_attrs[attr_cnt]);
381 if (ret) 384 if (ret)
382 goto err_out_files; 385 goto err_out_files;
383 } 386 }
@@ -393,8 +396,8 @@ int drm_sysfs_connector_add(struct drm_connector *connector)
393 case DRM_MODE_CONNECTOR_SVIDEO: 396 case DRM_MODE_CONNECTOR_SVIDEO:
394 case DRM_MODE_CONNECTOR_Component: 397 case DRM_MODE_CONNECTOR_Component:
395 case DRM_MODE_CONNECTOR_TV: 398 case DRM_MODE_CONNECTOR_TV:
396 for (i = 0; i < ARRAY_SIZE(connector_attrs_opt1); i++) { 399 for (opt_cnt = 0; opt_cnt < ARRAY_SIZE(connector_attrs_opt1); opt_cnt++) {
397 ret = device_create_file(&connector->kdev, &connector_attrs_opt1[i]); 400 ret = device_create_file(&connector->kdev, &connector_attrs_opt1[opt_cnt]);
398 if (ret) 401 if (ret)
399 goto err_out_files; 402 goto err_out_files;
400 } 403 }
@@ -413,10 +416,10 @@ int drm_sysfs_connector_add(struct drm_connector *connector)
413 return 0; 416 return 0;
414 417
415err_out_files: 418err_out_files:
416 if (i > 0) 419 for (i = 0; i < opt_cnt; i++)
417 for (j = 0; j < i; j++) 420 device_remove_file(&connector->kdev, &connector_attrs_opt1[i]);
418 device_remove_file(&connector->kdev, 421 for (i = 0; i < attr_cnt; i++)
419 &connector_attrs[i]); 422 device_remove_file(&connector->kdev, &connector_attrs[i]);
420 device_unregister(&connector->kdev); 423 device_unregister(&connector->kdev);
421 424
422out: 425out: