Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix division by zero if charging or discharging with no energy_rate #5

Merged
merged 1 commit into from
Feb 25, 2019

Conversation

kerhong
Copy link
Contributor

@kerhong kerhong commented Feb 25, 2019

When using battery-cli and unplugging the charger a division by zero happens because the battery is now in State::Discharging, but energy_rate is still 0.

@svartalf svartalf added C-bug Something isn't working O-linux Operating system: Linux A-battery Area: battery crate P-medium Medium priority labels Feb 25, 2019
@svartalf
Copy link
Owner

svartalf commented Feb 25, 2019

Unfortunately, I was not able to reproduce this case with my battery driver, guess that's why that bug appeared.

Do you mind to add a comment with short description and link to this PR? It seems to be a good idea to collect some knowledge base about possible edge cases.

@kerhong kerhong force-pushed the fix-division-by-zero-energy-rate branch 2 times, most recently from 237406c to b1b29ca Compare February 25, 2019 13:31
@kerhong kerhong force-pushed the fix-division-by-zero-energy-rate branch from b1b29ca to 21d19ba Compare February 25, 2019 13:32
@kerhong
Copy link
Contributor Author

kerhong commented Feb 25, 2019

Added a comment in code. More info about reproduction:

$ uname -a
Linux <redacted> 4.19.23-1-MANJARO #1 SMP PREEMPT Fri Feb 15 21:27:33 UTC 2019 x86_64 GNU/Linux
$ lshw | grep -A6 battery
  *-battery:0
       product: 45N1743
       vendor: SONY
       physical id: 1
       slot: Front
       capacity: 44460mWh
       configuration: voltage=11.4V
  *-battery:1
       product: 45N1127
       vendor: LGC
       physical id: 2
       slot: Rear
       capacity: 23480mWh
       configuration: voltage=11.4V
$ lshw | grep -A4 Motherboard
       description: Motherboard
       product: 20FH001TUS
       vendor: LENOVO
       physical id: 0
       version: SDK0J40705 WIN
$ lshw | grep -A4 Notebook
    description: Notebook
    product: 20FH001TUS (LENOVO_MT_20FH_BU_Think_FM_ThinkPad T560)
    vendor: LENOVO
    version: ThinkPad T560

The battery that starts discharging (and triggers the divsion by zero) is battery:1 from LGC

@svartalf svartalf merged commit dde37f4 into svartalf:master Feb 25, 2019
@svartalf
Copy link
Owner

Amazing, thank you!

I'll upload fix to the crates.io soon, depending if any other changes would appear today

davidkna pushed a commit to davidkna/rust-battery that referenced this pull request Jul 23, 2022
…/actions-rs/toolchain-1.0.7

Bump actions-rs/toolchain from 1.0.6 to 1.0.7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-battery Area: battery crate C-bug Something isn't working O-linux Operating system: Linux P-medium Medium priority
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants