Skip to contentSkip to conversation

drm, ttm Fix uninitialized warning

PATCH In review Prarit Bhargava 3 participants 3 messages Sep 13, 2013

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm, ttm Fix uninitialized warning

Fix uninitialized warning.

drivers/gpu/drm/ttm/ttm_object.c: In function ‘ttm_base_object_lookup’:
drivers/gpu/drm/ttm/ttm_object.c:213:10: error: ‘base’ may be used uninitialized in this function [-Werror=maybe-uninitialized]

  kref_put(&base->refcount, ttm_release_base);
          ^

drivers/gpu/drm/ttm/ttm_object.c:221:26: note: ‘base’ was declared here
struct ttm_base_object *base;

---
 drivers/gpu/drm/ttm/ttm_object.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/ttm/ttm_object.c +1 -1
index 58a5f32..a868176 100644
@@ -218,7 +218,7 @@ struct ttm_base_object *ttm_base_object_lookup(struct ttm_object_file *tfile,
 					       uint32_t key)
 {
 	struct ttm_object_device *tdev = tfile->tdev;
-	struct ttm_base_object *base;
+	struct ttm_base_object *uninitialized_var(base);
 	struct drm_hash_item *hash;
 	int ret;
 
Signature · 6 lines
1.7.9.3

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
Reviewed-by on v1 1/1
#1 lore raw
Quoted 4 lines · Prarit Bhargava

Fix uninitialized warning.

drivers/gpu/drm/ttm/ttm_object.c: In function ‘ttm_base_object_lookup’:
drivers/gpu/drm/ttm/ttm_object.c:213:10: error: ‘base’ may be used uninitialized in this function [-Werror=maybe-uninitialized]

Quoted 8 lines
  kref_put(&base->refcount, ttm_release_base);
          ^

drivers/gpu/drm/ttm/ttm_object.c:221:26: note: ‘base’ was declared here
struct ttm_base_object *base;

Quoted 24 lines
---
 drivers/gpu/drm/ttm/ttm_object.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/ttm/ttm_object.c +1 -2
index 58a5f32..a868176 100644
@@ -218,7 +218,7 @@ struct ttm_base_object *ttm_base_object_lookup(struct ttm_object_file *tfile,
                                               uint32_t key)
 {
        struct ttm_object_device *tdev = tfile->tdev;
-       struct ttm_base_object *base;
+       struct ttm_base_object *uninitialized_var(base);
        struct drm_hash_item *hash;
        int ret;
 
--

1.7.9.3

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

Reviewed-by on v1 1/1
#2 lore raw
In reply to Prarit Bhargava

Hi

Quoted 4 lines · Prarit Bhargava

Fix uninitialized warning.

drivers/gpu/drm/ttm/ttm_object.c: In function ‘ttm_base_object_lookup’:
drivers/gpu/drm/ttm/ttm_object.c:213:10: error: ‘base’ may be used uninitialized in this function [-Werror=maybe-uninitialized]

Quoted 8 lines
  kref_put(&base->refcount, ttm_release_base);
          ^

drivers/gpu/drm/ttm/ttm_object.c:221:26: note: ‘base’ was declared here
struct ttm_base_object *base;

Did some research on that, another fix is:

drivers/gpu/drm/ttm/ttm_object.c +0 -0
index 58a5f32..6b7f7b7 100644
@@ -228,7 +228,10 @@ struct ttm_base_object

*ttm_base_object_lookup(struct ttm_object_file *tfile,

        if (likely(ret == 0)) {
                base = drm_hash_entry(hash, struct ttm_base_object, hash);
                ret = kref_get_unless_zero(&base->refcount) ? 0 : -EINVAL;
+       } else {
+               ret = -EINVAL;
        }
+
        rcu_read_unlock();

        if (unlikely(ret != 0))

Looks totally stupid but also silences the warning. In fact, the warning is triggered by rcu_read_unlock(); and only if PROVE_LOCKING and DEBUG_LOCK_ALLOC are enabled. And it's related to the IP-size of the rcu_read_unlock() path.

I'd actually prefer "buf = NULL;" and an extended bail-out condition:
if (unlikely(ret != 0 || !buf))
but it's not my decision, so:

Cheers
David

Quoted 24 lines
---
 drivers/gpu/drm/ttm/ttm_object.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/ttm/ttm_object.c +1 -2
index 58a5f32..a868176 100644
@@ -218,7 +218,7 @@ struct ttm_base_object *ttm_base_object_lookup(struct ttm_object_file *tfile,
                                               uint32_t key)
 {
        struct ttm_object_device *tdev = tfile->tdev;
-       struct ttm_base_object *base;
+       struct ttm_base_object *uninitialized_var(base);
        struct drm_hash_item *hash;
        int ret;
 
--

1.7.9.3

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel