You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ac...@apache.org on 2026/10/08 18:52:51 UTC
(nuttx) branch master updated (e1f82fcc1cf -> 209f73ff0e1)
This is an automated email from the ASF dual-hosted git repository.
acassis pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
from e1f82fcc1cf audio: Fix the build with CONFIG_AUDIO_MULTI_SESSION.
new 6e7350d8c34 drivers/power: Fix nxstyle errors in battery_gauge.c.
new 209f73ff0e1 drivers/power: Do not call gauge methods a driver did not implement.
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
drivers/power/battery/battery_gauge.c | 108 ++++++++++++++++++++++++++++------
1 file changed, 90 insertions(+), 18 deletions(-)
(nuttx) 02/02: drivers/power: Do not call gauge methods a driver did not implement.
Posted by ac...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 209f73ff0e1a03ccad2589e014b263976892338c
Author: Marco Casaroli <ma...@gmail.com>
AuthorDate: Fri Jul 31 14:18:32 2026 +0200
drivers/power: Do not call gauge methods a driver did not implement.
Every BATIOC_* case in the gauge upper half calls dev->ops->X() after
checking only that the *argument* pointer is non-NULL. The operations
themselves are optional -- max1704x.c implements four of the eight, and
the in-tree fake gauge leaves chipid and operate NULL -- so asking a gauge
for something it does not provide calls through a NULL pointer.
On ARM that is not a null dereference but a branch to address 0, which has
the Thumb bit clear: the core takes a usage fault with CFSR bit 17,
INVSTATE, escalated to a hard fault. From userspace it looks like the
program stopped mid-run for no reason, and on a board whose assert path
delays before resetting it looks like a hang.
Guard all eight. A missing method is now ENOTTY, which is what the default
case already returns for an unrecognised command and what a caller can
sensibly probe for.
Tested on sim:nsh with the fake gauge and a local test app. Before the
change, ioctl(BATIOC_CHIPID) kills the simulator with SIGSEGV. After the
change, BATIOC_CHIPID and BATIOC_OPERATE return ENOTTY and
BATIOC_VOLTAGE still returns the voltage. nucleo-f412zg:nsh with
BATTERY_GAUGE, MAX1704X, BQ27426 and BATTERY_FAKE_GAUGE builds.
Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: Marco Casaroli <ma...@gmail.com>
---
drivers/power/battery/battery_gauge.c | 96 +++++++++++++++++++++++++++++------
1 file changed, 80 insertions(+), 16 deletions(-)
diff --git a/drivers/power/battery/battery_gauge.c b/drivers/power/battery/battery_gauge.c
index 101cca01c66..fbd52a293db 100644
--- a/drivers/power/battery/battery_gauge.c
+++ b/drivers/power/battery/battery_gauge.c
@@ -313,10 +313,18 @@ static int bat_gauge_ioctl(FAR struct file *filep,
{
FAR int *ptr = (FAR int *)((uintptr_t)arg);
- if (ptr)
+ if (ptr == NULL)
{
- ret = dev->ops->state(dev, ptr);
+ break;
}
+
+ if (dev->ops->state == NULL)
+ {
+ ret = -ENOTTY;
+ break;
+ }
+
+ ret = dev->ops->state(dev, ptr);
}
break;
@@ -324,10 +332,18 @@ static int bat_gauge_ioctl(FAR struct file *filep,
{
FAR bool *ptr = (FAR bool *)((uintptr_t)arg);
- if (ptr)
+ if (ptr == NULL)
{
- ret = dev->ops->online(dev, ptr);
+ break;
}
+
+ if (dev->ops->online == NULL)
+ {
+ ret = -ENOTTY;
+ break;
+ }
+
+ ret = dev->ops->online(dev, ptr);
}
break;
@@ -335,10 +351,18 @@ static int bat_gauge_ioctl(FAR struct file *filep,
{
FAR int *ptr = (FAR int *)((uintptr_t)arg);
- if (ptr)
+ if (ptr == NULL)
{
- ret = dev->ops->voltage(dev, ptr);
+ break;
}
+
+ if (dev->ops->voltage == NULL)
+ {
+ ret = -ENOTTY;
+ break;
+ }
+
+ ret = dev->ops->voltage(dev, ptr);
}
break;
@@ -346,10 +370,18 @@ static int bat_gauge_ioctl(FAR struct file *filep,
{
FAR int *ptr = (FAR int *)((uintptr_t)arg);
- if (ptr)
+ if (ptr == NULL)
{
- ret = dev->ops->capacity(dev, ptr);
+ break;
}
+
+ if (dev->ops->capacity == NULL)
+ {
+ ret = -ENOTTY;
+ break;
+ }
+
+ ret = dev->ops->capacity(dev, ptr);
}
break;
@@ -357,10 +389,18 @@ static int bat_gauge_ioctl(FAR struct file *filep,
{
FAR int *ptr = (FAR int *)((uintptr_t)arg);
- if (ptr)
+ if (ptr == NULL)
{
- ret = dev->ops->current(dev, ptr);
+ break;
}
+
+ if (dev->ops->current == NULL)
+ {
+ ret = -ENOTTY;
+ break;
+ }
+
+ ret = dev->ops->current(dev, ptr);
}
break;
@@ -368,10 +408,18 @@ static int bat_gauge_ioctl(FAR struct file *filep,
{
FAR int *ptr = (FAR int *)((uintptr_t)arg);
- if (ptr)
+ if (ptr == NULL)
{
- ret = dev->ops->temp(dev, ptr);
+ break;
}
+
+ if (dev->ops->temp == NULL)
+ {
+ ret = -ENOTTY;
+ break;
+ }
+
+ ret = dev->ops->temp(dev, ptr);
}
break;
@@ -379,10 +427,18 @@ static int bat_gauge_ioctl(FAR struct file *filep,
{
FAR unsigned int *ptr = (FAR unsigned int *)((uintptr_t)arg);
- if (ptr)
+ if (ptr == NULL)
{
- ret = dev->ops->chipid(dev, ptr);
+ break;
}
+
+ if (dev->ops->chipid == NULL)
+ {
+ ret = -ENOTTY;
+ break;
+ }
+
+ ret = dev->ops->chipid(dev, ptr);
}
break;
@@ -390,10 +446,18 @@ static int bat_gauge_ioctl(FAR struct file *filep,
{
FAR int *ptr = (FAR int *)((uintptr_t)arg);
- if (ptr)
+ if (ptr == NULL)
{
- ret = dev->ops->operate(dev, ptr);
+ break;
}
+
+ if (dev->ops->operate == NULL)
+ {
+ ret = -ENOTTY;
+ break;
+ }
+
+ ret = dev->ops->operate(dev, ptr);
}
break;
(nuttx) 01/02: drivers/power: Fix nxstyle errors in battery_gauge.c.
Posted by ac...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 6e7350d8c34838e36633ec8f7485f6236c377da6
Author: Marco Casaroli <ma...@gmail.com>
AuthorDate: Thu Oct 8 11:29:40 2026 +0200
drivers/power: Fix nxstyle errors in battery_gauge.c.
Whitespace only. Add a blank line after the declarations in the BATIOC_*
cases, and indent two case labels like the others. The errors are older
than the next commit, but checkpatch checks the whole file.
Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: Marco Casaroli <ma...@gmail.com>
---
drivers/power/battery/battery_gauge.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/drivers/power/battery/battery_gauge.c b/drivers/power/battery/battery_gauge.c
index 86c684e7448..101cca01c66 100644
--- a/drivers/power/battery/battery_gauge.c
+++ b/drivers/power/battery/battery_gauge.c
@@ -312,6 +312,7 @@ static int bat_gauge_ioctl(FAR struct file *filep,
case BATIOC_STATE:
{
FAR int *ptr = (FAR int *)((uintptr_t)arg);
+
if (ptr)
{
ret = dev->ops->state(dev, ptr);
@@ -322,6 +323,7 @@ static int bat_gauge_ioctl(FAR struct file *filep,
case BATIOC_ONLINE:
{
FAR bool *ptr = (FAR bool *)((uintptr_t)arg);
+
if (ptr)
{
ret = dev->ops->online(dev, ptr);
@@ -332,6 +334,7 @@ static int bat_gauge_ioctl(FAR struct file *filep,
case BATIOC_VOLTAGE:
{
FAR int *ptr = (FAR int *)((uintptr_t)arg);
+
if (ptr)
{
ret = dev->ops->voltage(dev, ptr);
@@ -342,6 +345,7 @@ static int bat_gauge_ioctl(FAR struct file *filep,
case BATIOC_CAPACITY:
{
FAR int *ptr = (FAR int *)((uintptr_t)arg);
+
if (ptr)
{
ret = dev->ops->capacity(dev, ptr);
@@ -349,9 +353,10 @@ static int bat_gauge_ioctl(FAR struct file *filep,
}
break;
- case BATIOC_CURRENT:
+ case BATIOC_CURRENT:
{
FAR int *ptr = (FAR int *)((uintptr_t)arg);
+
if (ptr)
{
ret = dev->ops->current(dev, ptr);
@@ -359,9 +364,10 @@ static int bat_gauge_ioctl(FAR struct file *filep,
}
break;
- case BATIOC_TEMPERATURE:
+ case BATIOC_TEMPERATURE:
{
FAR int *ptr = (FAR int *)((uintptr_t)arg);
+
if (ptr)
{
ret = dev->ops->temp(dev, ptr);
@@ -372,6 +378,7 @@ static int bat_gauge_ioctl(FAR struct file *filep,
case BATIOC_CHIPID:
{
FAR unsigned int *ptr = (FAR unsigned int *)((uintptr_t)arg);
+
if (ptr)
{
ret = dev->ops->chipid(dev, ptr);
@@ -382,6 +389,7 @@ static int bat_gauge_ioctl(FAR struct file *filep,
case BATIOC_OPERATE:
{
FAR int *ptr = (FAR int *)((uintptr_t)arg);
+
if (ptr)
{
ret = dev->ops->operate(dev, ptr);