drivers: fuel_gauge: make read-only pointer args const in api

For the lists of properties passed as a pointer to the get_props and
set_props functions, there is no reason to not make the pointer const as
the called functions will not and should not alter the pointed-to data.

In practice, not having the pointers const can cause compilation errors
if trying to pass in a const array of properties.

Signed-off-by: Mikkel Jakobsen <mikkel.aunsbjerg@escolifesciences.com>
This commit is contained in:
Mikkel Jakobsen 2024-12-19 14:36:26 +01:00 committed by Benjamin Cabé
parent 7960747d8d
commit e4c21da41b
3 changed files with 15 additions and 16 deletions

View file

@ -26,7 +26,8 @@ static inline int z_vrfy_fuel_gauge_get_prop(const struct device *dev, fuel_gaug
#include <zephyr/syscalls/fuel_gauge_get_prop_mrsh.c>
static inline int z_vrfy_fuel_gauge_get_props(const struct device *dev, fuel_gauge_prop_t *props,
static inline int z_vrfy_fuel_gauge_get_props(const struct device *dev,
const fuel_gauge_prop_t *props,
union fuel_gauge_prop_val *vals, size_t len)
{
union fuel_gauge_prop_val k_vals[len];
@ -58,8 +59,9 @@ static inline int z_vrfy_fuel_gauge_set_prop(const struct device *dev, fuel_gaug
#include <zephyr/syscalls/fuel_gauge_set_prop_mrsh.c>
static inline int z_vrfy_fuel_gauge_set_props(const struct device *dev, fuel_gauge_prop_t *props,
union fuel_gauge_prop_val *vals, size_t len)
static inline int z_vrfy_fuel_gauge_set_props(const struct device *dev,
const fuel_gauge_prop_t *props,
const union fuel_gauge_prop_val *vals, size_t len)
{
union fuel_gauge_prop_val k_vals[len];
fuel_gauge_prop_t k_props[len];
@ -71,9 +73,6 @@ static inline int z_vrfy_fuel_gauge_set_props(const struct device *dev, fuel_gau
int ret = z_impl_fuel_gauge_set_props(dev, k_props, k_vals, len);
/* We only copy back vals because props will never be modified */
K_OOPS(k_usermode_to_copy(vals, k_vals, len * sizeof(union fuel_gauge_prop_val)));
return ret;
}

View file

@ -288,10 +288,10 @@ static inline int z_impl_fuel_gauge_get_prop(const struct device *dev, fuel_gaug
* @return 0 if successful, negative errno code of first failing property
*/
__syscall int fuel_gauge_get_props(const struct device *dev, fuel_gauge_prop_t *props,
__syscall int fuel_gauge_get_props(const struct device *dev, const fuel_gauge_prop_t *props,
union fuel_gauge_prop_val *vals, size_t len);
static inline int z_impl_fuel_gauge_get_props(const struct device *dev,
fuel_gauge_prop_t *props,
const fuel_gauge_prop_t *props,
union fuel_gauge_prop_val *vals, size_t len)
{
const struct fuel_gauge_driver_api *api = (const struct fuel_gauge_driver_api *)dev->api;
@ -342,12 +342,12 @@ static inline int z_impl_fuel_gauge_set_prop(const struct device *dev, fuel_gaug
*
* @return return=0 if successful. Otherwise, return array index of failing property.
*/
__syscall int fuel_gauge_set_props(const struct device *dev, fuel_gauge_prop_t *props,
union fuel_gauge_prop_val *vals, size_t len);
__syscall int fuel_gauge_set_props(const struct device *dev, const fuel_gauge_prop_t *props,
const union fuel_gauge_prop_val *vals, size_t len);
static inline int z_impl_fuel_gauge_set_props(const struct device *dev,
fuel_gauge_prop_t *props,
union fuel_gauge_prop_val *vals, size_t len)
const fuel_gauge_prop_t *props,
const union fuel_gauge_prop_val *vals, size_t len)
{
for (size_t i = 0; i < len; i++) {
int ret = fuel_gauge_set_prop(dev, props[i], vals[i]);

View file

@ -42,7 +42,7 @@ ZTEST_USER_F(sbs_gauge_new_api, test_get_some_props_failed_returns_bad_status)
/* Valid property */
FUEL_GAUGE_VOLTAGE,
};
union fuel_gauge_prop_val props[ARRAY_SIZE(prop_types)];
union fuel_gauge_prop_val props[ARRAY_SIZE(prop_types)] = {0};
int ret = fuel_gauge_get_props(fixture->dev, prop_types, props, ARRAY_SIZE(props));
@ -55,7 +55,7 @@ ZTEST_USER_F(sbs_gauge_new_api, test_set_all_props_failed_returns_err)
/* Invalid property */
FUEL_GAUGE_PROP_MAX,
};
union fuel_gauge_prop_val props[ARRAY_SIZE(prop_types)];
union fuel_gauge_prop_val props[ARRAY_SIZE(prop_types)] = {0};
int ret = fuel_gauge_set_props(fixture->dev, prop_types, props, ARRAY_SIZE(props));
@ -166,7 +166,7 @@ ZTEST_USER_F(sbs_gauge_new_api, test_get_props__returns_ok)
FUEL_GAUGE_SBS_REMAINING_TIME_ALARM,
};
union fuel_gauge_prop_val props[ARRAY_SIZE(prop_types)];
union fuel_gauge_prop_val props[ARRAY_SIZE(prop_types)] = {0};
zassert_ok(fuel_gauge_get_props(fixture->dev, prop_types, props, ARRAY_SIZE(props)));
}
@ -181,7 +181,7 @@ ZTEST_USER_F(sbs_gauge_new_api, test_set_props__returns_ok)
FUEL_GAUGE_SBS_REMAINING_CAPACITY_ALARM,
};
union fuel_gauge_prop_val props[ARRAY_SIZE(prop_types)];
union fuel_gauge_prop_val props[ARRAY_SIZE(prop_types)] = {0};
zassert_ok(fuel_gauge_set_props(fixture->dev, prop_types, props, ARRAY_SIZE(props)));
}