Bug 454161

Summary: Brightness stuck at 30%
Product: [Plasma] Powerdevil Reporter: Sparkwave <Plazmoid3>
Component: generalAssignee: ratijas <me>
Status: RESOLVED FIXED    
Severity: major CC: alej.c.s, alejandrosena, andrea.ippo, asturm, brunopitrus, cbdude, contact, cornelis, coucouf, davmor2, eduardp, fedux, jramirez.uy, kde, laimislsecond, luisbocanegra17b, Mathias.Homann, me, me, meven29, nate, patrick, poomklao, RaitaroHikami, rikmills, rohan, sam, tromzy
Priority: VHI Keywords: regression
Version: 5.24.90   
Target Milestone: ---   
Platform: Neon   
OS: Linux   
Latest Commit: Version Fixed In: 5.25.1

Description Sparkwave 2022-05-21 14:49:37 UTC
SUMMARY
If the laptop is set to set its brightness to 30% upon reaching low battery, it will keep its brightness below 30% even after  the battery is fully charged and plugged in, and won't allow the user to set its brightness above 30% even after reboot, both with the hardware brightness keys and with the system brightness slider.

STEPS TO REPRODUCE
1. Set Plasma to lower the screen brightness to 30% at low battery
2. Wait until the device reaches low battery
3. Try to increase the brightness back up

OBSERVED RESULT
The brightness will snap back to 0% upon reaching 30%

EXPECTED RESULT
The brightness should continue being able to increase beyond 30%

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: Arch Linux (Arch Linux Packages)
KDE Plasma Version: 5.24.90
KDE Frameworks Version: 5.94.0
Qt Version: 5.15.4

ADDITIONAL INFORMATION
Comment 1 luisbocanegra 2022-05-23 06:15:55 UTC
I'm having this bug too, in my case it happens even when with the brightness setting disabled in Energy Saving options.

Trying to set it manually is also affected:
```sh
qdbus local.org_kde_powerdevil /org/kde/Solid/PowerManagement/Actions/BrightnessControl org.kde.Solid.PowerManagement.Actions.BrightnessControl.setBrightness 40000
```

While:
```sh
echo 40000 | sudo tee /sys/class/backlight/intel_backlight/brightness
```
works

SOFTWARE/OS VERSIONS (Same as reporter)
Linux/KDE Plasma: Arch Linux (Arch Linux Packages)
KDE Plasma Version: 5.24.90
KDE Frameworks Version: 5.94.0
Qt Version: 5.15.4
Kernel Version: 5.17.9-arch1-1 (64-bit)
Graphics Platform: X11

HARDWARE
Processors: Intel i7-9750H
Graphics Processor: Mesa Intel® UHD Graphics 630
Manufacturer: HP
Product Name: OMEN by HP Laptop 15-dc1xxx
Comment 2 Bruno Pitrus 2022-05-25 14:10:18 UTC
Seems to be same as this SUSE bug:
https://bugzilla.opensuse.org/show_bug.cgi?id=1199907
Comment 3 Aurélien COUDERC 2022-05-31 13:57:30 UTC
Same issue on Debian unstable working on packaging 5.25 beta.

Others (at least from Kubuntu) don’t have the issue so not sure if the hardware or kernel is involved.
My kernel is 5.17.6, and the laptop an XPS 13 7390.

The issue is linked to the following commit :
    Write brightness to all raw devices
    https://invent.kde.org/plasma/powerdevil/-/commit/761fc8a4bf4bd70bcd9aca63fc67382c94ecf884

Reverting it and its followup :
    Fix Commit 761fc8a4
    https://invent.kde.org/plasma/powerdevil/-/commit/94f8186804d8a67459a11673b602c55e34db25ad

fixes the issue for me.
Comment 4 Aurélien COUDERC 2022-05-31 14:14:13 UTC
Quick note to say that for me it’s a serious bug.

The brightness I get with the bug is more around 20% and makes it barely usable during daytime.
Comment 5 Nate Graham 2022-06-07 18:02:34 UTC
It does seem hardware-dependent. I cannot reproduce with my laptop that has an Intel HD 620 iGPU and no dedicated GPU. I'm CCing some people who might be able to help, and will ping the original author.
Comment 6 Nate Graham 2022-06-14 18:17:07 UTC
Are you using the slider in the Battery & Brightness applet? Does it work if you click on a position in the track rather than dragging the handle?
Comment 7 Nate Graham 2022-06-14 18:17:11 UTC
*** Bug 455256 has been marked as a duplicate of this bug. ***
Comment 8 Sam James 2022-06-14 20:20:38 UTC
(In reply to Aurélien COUDERC from comment #3)
> Same issue on Debian unstable working on packaging 5.25 beta.
> 
> https://invent.kde.org/plasma/powerdevil/-/commit/
> 761fc8a4bf4bd70bcd9aca63fc67382c94ecf884
> https://invent.kde.org/plasma/powerdevil/-/commit/
> 94f8186804d8a67459a11673b602c55e34db25ad
> 

Thanks. Reverting these sorts out the issue for me too.

Gentoo, KDE Plasma 5.25, Frameworks 5.95.0.
Dell XPS 15 9510, but using Intel graphics.
Comment 9 Aurélien COUDERC 2022-06-14 22:45:48 UTC
(In reply to Nate Graham from comment #6)
> Are you using the slider in the Battery & Brightness applet? Does it work if
> you click on a position in the track rather than dragging the handle?

I’ve reverted the commits for some time now, but as far as I remember both the slider and the keys had the same effect.

It was not only blocking at ~20 % but the brightness was also flickering between steps until it reached that level. So it would do something like 6%, 8%, 2%, 12%, 1%, 16%, 3%, 18% (not precisely these numbers but you get the idea).
Comment 10 poomklao 2022-06-15 08:30:46 UTC
"Me-too"-ing this bug.
* For me, this happens without the laptop ever going below 30% post-update.
* Both the slider and the keys have the same effect.
Comment 11 tromzy 2022-06-15 09:19:08 UTC
I'm having the same issue : https://bugs.kde.org/show_bug.cgi?id=455307
Comment 12 Patrick van Elk 2022-06-15 09:24:56 UTC
Temporary workaround for KDE Neon:

sudo apt install powerdevil=4:5.24.5-0xneon+20.04+focal+release+build47 powerdevil-data=4:5.24.5-0xneon+20.04+focal+release+build47
Comment 13 Sam James 2022-06-15 15:37:37 UTC
*** Bug 455307 has been marked as a duplicate of this bug. ***
Comment 14 Sam James 2022-06-15 15:38:24 UTC
*** Bug 455308 has been marked as a duplicate of this bug. ***
Comment 15 Antonio Rojas 2022-06-15 17:46:06 UTC
*** Bug 455347 has been marked as a duplicate of this bug. ***
Comment 16 Antonio Rojas 2022-06-15 17:47:42 UTC
*** Bug 455348 has been marked as a duplicate of this bug. ***
Comment 17 eduard 2022-06-15 20:19:24 UTC
Same workaround for KUbuntu :

sudo apt install powerdevil=4:5.24.4-0ubuntu1 powerdevil-data=4:5.24.4-0ubuntu1 libpowerdevilcore2=4:5.24.4-0ubuntu1 libpowerdevilui5=4:5.24.4-0ubuntu1
Comment 18 Bug Janitor Service 2022-06-15 21:48:12 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/powerdevil/-/merge_requests/94
Comment 19 Nate Graham 2022-06-15 22:15:42 UTC
Can affected folks test that patch? ^^
Comment 20 ichramm 2022-06-15 22:36:35 UTC
(In reply to Nate Graham from comment #19)
> Can affected folks test that patch? ^^

It works! (KDE Neon User Edition on Dell XPS 7590).

Steps:

* Created a new branch over the tag v5.25.0
* Cherry-picked Ivan's commit
* cd build && cmake .. && make && sudo make install
Comment 21 alejandrosena 2022-06-16 01:25:30 UTC
Same happening here

Operating System: KDE neon 5.25
KDE Plasma Version: 5.25.0
KDE Frameworks Version: 5.95.0
Qt Version: 5.15.4
Kernel Version: 5.13.0-48-generic (64-bit)
Graphics Platform: X11
Graphics Processor: Mesa Intel® UHD Graphics 620
Comment 22 Sam James 2022-06-16 01:56:54 UTC
(In reply to Nate Graham from comment #19)
> Can affected folks test that patch? ^^

Works for me.
Comment 23 Aurélien COUDERC 2022-06-16 05:32:26 UTC
(In reply to Nate Graham from comment #19)
> Can affected folks test that patch? ^^

Works for me on top of the Debian package on an XPS 7390.
Comment 24 Antonio Rojas 2022-06-16 07:13:15 UTC
*** Bug 455381 has been marked as a duplicate of this bug. ***
Comment 25 Antonio Rojas 2022-06-16 07:36:22 UTC
*** Bug 455382 has been marked as a duplicate of this bug. ***
Comment 26 K900 2022-06-16 08:21:40 UTC
Also works for me on Dell Latitude 5420.
Comment 27 Mathias Homann 2022-06-16 08:26:25 UTC
Works for me on a MSI Prestige 14 running openSUSE Tumbleweed. RPMs for Tumbleweed containing that fix can be found on OBS at
https://build.opensuse.org/package/show/home:lemmy04:branches:KDE:Frameworks5/powerdevil5
Comment 28 cbdude 2022-06-16 16:54:34 UTC
Same issue here in KDE Neon, thanks to Patrick van Elk for the workaround 

sudo apt install powerdevil=4:5.24.5-0xneon+20.04+focal+release+build47 powerdevil-data=4:5.24.5-0xneon+20.04+focal+release+build47
Comment 29 ratijas 2022-06-16 18:14:13 UTC
Git commit 2ebe655d220c9167b66893a823b2fff2e2b8a531 by ivan tkachenko.
Committed on 15/06/2022 at 22:24.
Pushed by ratijas into branch 'master'.

upower: Prevent integer overflow during new brightness computation

Provably, if two integers can fit in 31 bits each, the result of their
multiplication is expressible in 62 bits (let alone 63 available). So,
this should be safe. And the division can't do much harm: the divisor
is always at least 1, and worst case scenario — it would be so big that
the overall results becomes zero.

This code still assumes that the allowed brightness values can fit in 32
bits int, which is not totally unreasonable so far.

M  +7    -4    daemon/backends/upower/backlighthelper.cpp

https://invent.kde.org/plasma/powerdevil/commit/2ebe655d220c9167b66893a823b2fff2e2b8a531
Comment 30 ratijas 2022-06-16 18:18:03 UTC
Git commit dd74cdbdd3849fbd86e6613ef7ecab6c7857cb89 by ivan tkachenko.
Committed on 16/06/2022 at 18:17.
Pushed by ratijas into branch 'Plasma/5.25'.

upower: Prevent integer overflow during new brightness computation

Provably, if two integers can fit in 31 bits each, the result of their
multiplication is expressible in 62 bits (let alone 63 available). So,
this should be safe. And the division can't do much harm: the divisor
is always at least 1, and worst case scenario — it would be so big that
the overall results becomes zero.

This code still assumes that the allowed brightness values can fit in 32
bits int, which is not totally unreasonable so far.


(cherry picked from commit 2ebe655d220c9167b66893a823b2fff2e2b8a531)

M  +7    -4    daemon/backends/upower/backlighthelper.cpp

https://invent.kde.org/plasma/powerdevil/commit/dd74cdbdd3849fbd86e6613ef7ecab6c7857cb89
Comment 31 poomklao 2022-06-17 03:49:34 UTC
Note to self: Affected version of powerdevil is 4:5.25.0-0xneon+20.04+focal+release+build49
Comment 32 MiXiM 2022-06-23 05:50:06 UTC
Hi, same issue here in KDE Neon,
Dell XPS15 9570, latest stable updates,
 thanks to Patrick van Elk for the workaround,
works 4 me 2

sudo apt install powerdevil=4:5.24.5-0xneon+20.04+focal+release+build47 powerdevil-data=4:5.24.5-0xneon+20.04+focal+release+build47
Comment 33 Nate Graham 2022-06-27 21:11:57 UTC
*** Bug 455256 has been marked as a duplicate of this bug. ***
Comment 34 Nate Graham 2022-06-30 18:07:16 UTC
*** Bug 455960 has been marked as a duplicate of this bug. ***