Skip to contentSkip to conversation

drm/nouveau/led: don't access led subdev if it wasn't initialized

PATCH In review Martin Peres 3 participants 10 messages Sep 16, 2016 – Sep 17, 2016 5 messages not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 drm/nouveau/led: don't access led subdev if it wasn't initialized

From: Karol Herbst <[email protected]>

Fixes a kernel crash on suspend/resume.

---
 drm/nouveau/nouveau_led.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drm/nouveau/nouveau_led.c +4 -3
index 9eed5a6..5e28b5f 100644
@@ -107,7 +107,8 @@ nouveau_led_suspend(struct drm_device *dev)
 {
 	struct nouveau_drm *drm = nouveau_drm(dev);
 
-	led_classdev_suspend(&drm->led->led);
+	if (drm->led)
+		led_classdev_suspend(&drm->led->led);
 }
 
 void
@@ -115,8 +116,8 @@ nouveau_led_resume(struct drm_device *dev)
 {
 	struct nouveau_drm *drm = nouveau_drm(dev);
 
-	led_classdev_resume(&drm->led->led);
-
+	if (drm->led)
+		led_classdev_resume(&drm->led->led);
 }
 
 void
Signature · 6 lines
2.8.0

_______________________________________________
Nouveau mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/nouveau

A message that is not in the archive (sent off-list or not yet received): [email protected]

#2 lore raw

PATCH 2/3 drm/nouveau/led: guard against a division by 0

---
 drm/nouveau/nouveau_led.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drm/nouveau/nouveau_led.c +4 -1
index 5e28b5f..1f731da 100644
@@ -44,7 +44,10 @@ nouveau_led_get_brightness(struct led_classdev *led)
 	div =  nvif_rd32(device, 0x61c880) & 0x00ffffff;
 	duty = nvif_rd32(device, 0x61c884) & 0x00ffffff;
 
-	return duty * LED_FULL / div;
+	if (div > 0)
+		return duty * LED_FULL / div;
+	else
+		return 0;
 }
 
 static void
Signature · 6 lines
2.8.0

_______________________________________________
Nouveau mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/nouveau

A message that is not in the archive (sent off-list or not yet received): [email protected]

Reviewed-by
#5 lore raw

Re: [PATCH 2/3] drm/nouveau/led: guard against a division by 0

In reply to a message not in the archive

2016-09-16 9:34 GMT+02:00 Martin Peres <[email protected]>:

Quoted 10 lines
---
 drm/nouveau/nouveau_led.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drm/nouveau/nouveau_led.c +0 -0
index 5e28b5f..1f731da 100644

drm/nouveau/nouveau_led.c nouveau_led_get_brightness(struct led_classdev *led) · line 50

Quoted 8 lines
drm/nouveau/nouveau_led.c +4 -1
@@ -44,7 +44,10 @@ nouveau_led_get_brightness(struct led_classdev *led)
        div =  nvif_rd32(device, 0x61c880) & 0x00ffffff;
        duty = nvif_rd32(device, 0x61c884) & 0x00ffffff;
 
-       return duty * LED_FULL / div;
+       if (div > 0)
+               return duty * LED_FULL / div;
+       else
+               return 0;

minor nitpick: you can drop the else, I don't mind though. Maybe it would be clearer to do it the other way around though.

Or to do:

if (unlikely(div <= 0)) return 0;
return duty * LED_FULL / div;

Quoted 10 lines
drm/nouveau/nouveau_led.c +0 -1
 }
 
 static void
--

2.8.0

_______________________________________________
Nouveau mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/nouveau

_______________________________________________
Nouveau mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/nouveau

A message that is not in the archive (sent off-list or not yet received): CAEXux-bN4EsMMW1Y9qaNwfE3pjFO=a9qaKEoBC3-Xijvh57zRA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#7 lore raw

Re: [PATCH 2/3] drm/nouveau/led: guard against a division by 0

Quoted 24 lines · Karol Herbst

2016-09-16 9:34 GMT+02:00 Martin Peres <[email protected]>:

Quoted 10 lines
---
  drm/nouveau/nouveau_led.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
drm/nouveau/nouveau_led.c +0 -0
index 5e28b5f..1f731da 100644

drm/nouveau/nouveau_led.c nouveau_led_get_brightness(struct led_classdev *led) · line 50

Quoted 8 lines
drm/nouveau/nouveau_led.c +4 -1
@@ -44,7 +44,10 @@ nouveau_led_get_brightness(struct led_classdev *led)
         div =  nvif_rd32(device, 0x61c880) & 0x00ffffff;
         duty = nvif_rd32(device, 0x61c884) & 0x00ffffff;
 
-       return duty * LED_FULL / div;
+       if (div > 0)
+               return duty * LED_FULL / div;
+       else
+               return 0;

minor nitpick: you can drop the else, I don't mind though. Maybe it would be clearer to do it the other way around though.

Quoted 4 lines

Or to do:

if (unlikely(div <= 0)) return 0;
return duty * LED_FULL / div;

The unlikely is a good idea, not a fan of single lines if conditions though :s
_______________________________________________
Nouveau mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/nouveau

A message that is not in the archive (sent off-list or not yet received): 776cc8a8-a36e-7b4f-9240-f63773fea33f-GANU6spQydw@public.gmane.org

#9 lore raw

Re: [PATCH 2/3] drm/nouveau/led: guard against a division by 0

2016-09-16 11:14 GMT+02:00 Martin Peres <[email protected]>:

Quoted 28 lines · Karol Herbst
Quoted 27 lines

2016-09-16 9:34 GMT+02:00 Martin Peres <[email protected]>:

Quoted 11 lines
---
  drm/nouveau/nouveau_led.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
drm/nouveau/nouveau_led.c +0 -0
index 5e28b5f..1f731da 100644

drm/nouveau/nouveau_led.c nouveau_led_get_brightness(struct led_classdev *led) · line 50

Quoted 8 lines
drm/nouveau/nouveau_led.c +4 -1
@@ -44,7 +44,10 @@ nouveau_led_get_brightness(struct led_classdev *led)
         div =  nvif_rd32(device, 0x61c880) & 0x00ffffff;
         duty = nvif_rd32(device, 0x61c884) & 0x00ffffff;
 
-       return duty * LED_FULL / div;
+       if (div > 0)
+               return duty * LED_FULL / div;
+       else
+               return 0;

minor nitpick: you can drop the else, I don't mind though. Maybe it would be clearer to do it the other way around though.

Quoted 8 lines
Quoted 4 lines

Or to do:

if (unlikely(div <= 0)) return 0;
return duty * LED_FULL / div;

The unlikely is a good idea, not a fan of single lines if conditions though :s

the single line was me being lazy.

if (unlikely(div <= 0))

        return 0;

return duty * LED_FULL / div;

:p
_______________________________________________
Nouveau mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/nouveau

#10 lore raw

PATCH 3/3 drm/nouveau/led: abort early if the device does not have GPIOs

In reply to a message not in the archive
---
 drm/nouveau/nouveau_led.c | 3 +++
 1 file changed, 3 insertions(+)
drm/nouveau/nouveau_led.c +3 -0
index 1f731da..3e2f1b6 100644
@@ -82,6 +82,9 @@ nouveau_led_init(struct drm_device *dev)
 	struct dcb_gpio_func logo_led;
 	int ret;
 
+	if (!gpio)
+		return 0;
+
 	/* check that there is a GPIO controlling the logo LED */
 	if (nvkm_gpio_find(gpio, 0, DCB_GPIO_LOGO_LED_PWM, 0xff, &logo_led))
 		return 0;
Signature · 6 lines
2.8.0

_______________________________________________
Nouveau mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/nouveau

A message that is not in the archive (sent off-list or not yet received): [email protected]

Reviewed-by
#13 lore raw

Re: [PATCH 3/3] drm/nouveau/led: abort early if the device does not have GPIOs

In reply to a message not in the archive

2016-09-16 9:34 GMT+02:00 Martin Peres <[email protected]>:

Quoted 22 lines
---
 drm/nouveau/nouveau_led.c | 3 +++
 1 file changed, 3 insertions(+)
drm/nouveau/nouveau_led.c +3 -1
index 1f731da..3e2f1b6 100644
@@ -82,6 +82,9 @@ nouveau_led_init(struct drm_device *dev)
        struct dcb_gpio_func logo_led;
        int ret;
 
+       if (!gpio)
+               return 0;
+
        /* check that there is a GPIO controlling the logo LED */
        if (nvkm_gpio_find(gpio, 0, DCB_GPIO_LOGO_LED_PWM, 0xff, &logo_led))
                return 0;
--

2.8.0

Quoted 4 lines

_______________________________________________
Nouveau mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/nouveau

_______________________________________________
Nouveau mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/nouveau

#14 lore raw

PATCH 1/1 drm/nouveau/led: make all the stub functions static inline

In reply to a message not in the archive
---
 drm/nouveau/nouveau_led.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drm/nouveau/nouveau_led.h +3 -3
index 750a0d9..187ecdb 100644
@@ -49,9 +49,9 @@ void nouveau_led_resume(struct drm_device *dev);
 void nouveau_led_fini(struct drm_device *dev);
 #else
 static inline int  nouveau_led_init(struct drm_device *dev) { return 0; };
-void nouveau_led_suspend(struct drm_device *dev) { return; };
-void nouveau_led_resume(struct drm_device *dev) { return; };
-void nouveau_led_fini(struct drm_device *dev) { return; };
+static inline void nouveau_led_suspend(struct drm_device *dev) { };
+static inline void nouveau_led_resume(struct drm_device *dev) { };
+static inline void nouveau_led_fini(struct drm_device *dev) { };
 #endif
 
 #endif
Signature · 6 lines
2.8.0

_______________________________________________
Nouveau mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/nouveau