linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [patch] drm: sysfs files error handling
@ 2010-03-28 11:24 Dan Carpenter
  2010-03-28 20:55 ` Andi Kleen
  0 siblings, 1 reply; 3+ messages in thread
From: Dan Carpenter @ 2010-03-28 11:24 UTC (permalink / raw)
  To: David Airlie
  Cc: Greg Kroah-Hartman, Andi Kleen, Thomas Hellstrom, Jesse Barnes,
	dri-devel, linux-kernel, kernel-janitors


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>
---
Found by static analysis and compile tested only.

diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c
index 014ce24..f144487 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 = {
 int drm_sysfs_connector_add(struct drm_connector *connector)
 {
 	struct drm_device *dev = connector->dev;
-	int ret = 0, i, j;
+	int attr_cnt = 0;
+	int opt_cnt = 0;
+	int i;
+	int ret = 0;
 
 	/* We shouldn't get called more than once for the same connector */
 	BUG_ON(device_is_registered(&connector->kdev));
@@ -376,8 +379,8 @@ int drm_sysfs_connector_add(struct drm_connector *connector)
 
 	/* Standard attributes */
 
-	for (i = 0; i < ARRAY_SIZE(connector_attrs); i++) {
-		ret = device_create_file(&connector->kdev, &connector_attrs[i]);
+	for (attr_cnt = 0; attr_cnt < ARRAY_SIZE(connector_attrs); attr_cnt++) {
+		ret = device_create_file(&connector->kdev, &connector_attrs[attr_cnt]);
 		if (ret)
 			goto err_out_files;
 	}
@@ -393,8 +396,8 @@ int drm_sysfs_connector_add(struct drm_connector *connector)
 		case DRM_MODE_CONNECTOR_SVIDEO:
 		case DRM_MODE_CONNECTOR_Component:
 		case DRM_MODE_CONNECTOR_TV:
-			for (i = 0; i < ARRAY_SIZE(connector_attrs_opt1); i++) {
-				ret = device_create_file(&connector->kdev, &connector_attrs_opt1[i]);
+			for (opt_cnt = 0; opt_cnt < ARRAY_SIZE(connector_attrs_opt1); opt_cnt++) {
+				ret = device_create_file(&connector->kdev, &connector_attrs_opt1[opt_cnt]);
 				if (ret)
 					goto err_out_files;
 			}
@@ -413,10 +416,10 @@ int drm_sysfs_connector_add(struct drm_connector *connector)
 	return 0;
 
 err_out_files:
-	if (i > 0)
-		for (j = 0; j < i; j++)
-			device_remove_file(&connector->kdev,
-					   &connector_attrs[i]);
+	for (i = 0; i < opt_cnt; i++)
+		device_remove_file(&connector->kdev, &connector_attrs_opt1[i]);
+	for (i = 0; i < attr_cnt; i++)
+		device_remove_file(&connector->kdev, &connector_attrs[i]);
 	device_unregister(&connector->kdev);
 
 out:

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [patch] drm: sysfs files error handling
  2010-03-28 11:24 [patch] drm: sysfs files error handling Dan Carpenter
@ 2010-03-28 20:55 ` Andi Kleen
  2010-03-30 14:44   ` Dan Carpenter
  0 siblings, 1 reply; 3+ messages in thread
From: Andi Kleen @ 2010-03-28 20:55 UTC (permalink / raw)
  To: Dan Carpenter, David Airlie, Greg Kroah-Hartman,
	Thomas Hellstrom, Jesse Barnes, dri-devel, linux-kernel,
	kernel-janitors

, Dan Carpenter wrote:
>
> 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]);

I guess this really should be a attribute group anyways?

Typically when there's such a open coded loop it means the wrong
interfaces are being used.

-Andi


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [patch] drm: sysfs files error handling
  2010-03-28 20:55 ` Andi Kleen
@ 2010-03-30 14:44   ` Dan Carpenter
  0 siblings, 0 replies; 3+ messages in thread
From: Dan Carpenter @ 2010-03-30 14:44 UTC (permalink / raw)
  To: Andi Kleen
  Cc: David Airlie, Greg Kroah-Hartman, Thomas Hellstrom, Jesse Barnes,
	dri-devel, linux-kernel, kernel-janitors

On Sun, Mar 28, 2010 at 10:55:14PM +0200, Andi Kleen wrote:
> , Dan Carpenter wrote:
>>
>> 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]);
>
> I guess this really should be a attribute group anyways?
>
> Typically when there's such a open coded loop it means the wrong
> interfaces are being used.

My graphics card is crap and doesn't use this code at all.  I'd feel 
uncomfortable those changes without being able to test it.

So while, you are probably right, someone else should probably do that.

regards,
dan carpenter

> -Andi

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-03-30 14:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-03-28 11:24 [patch] drm: sysfs files error handling Dan Carpenter
2010-03-28 20:55 ` Andi Kleen
2010-03-30 14:44   ` Dan Carpenter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).