Skip to content

Commit 50a044a

Browse files
dleach02kartben
authored andcommitted
drivers: sensor: fxls8974: fix size misalignment memory access
Coverity identified out-of-bounds access. A uint8_t being cast to an enum is undefined in that the enum can be allocated 4bytes. Change the internal function to use the base type of the variable, uint8_t to avoid potential compiler size alignement problems. Fixes #81927 Signed-off-by: David Leach <[email protected]>
1 parent 83a45f4 commit 50a044a

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

drivers/sensor/nxp/fxls8974/fxls8974.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ static int fxls8974_channel_get(const struct device *dev,
399399
return 0;
400400
}
401401

402-
int fxls8974_get_active(const struct device *dev, enum fxls8974_active *active)
402+
int fxls8974_get_active(const struct device *dev, uint8_t *active)
403403
{
404404
const struct fxls8974_config *cfg = dev->config;
405405
uint8_t val;
@@ -415,7 +415,7 @@ int fxls8974_get_active(const struct device *dev, enum fxls8974_active *active)
415415
return 0;
416416
}
417417

418-
int fxls8974_set_active(const struct device *dev, enum fxls8974_active active)
418+
int fxls8974_set_active(const struct device *dev, uint8_t active)
419419
{
420420
const struct fxls8974_config *cfg = dev->config;
421421

@@ -498,7 +498,7 @@ static int fxls8974_init(const struct device *dev)
498498
return -EIO;
499499
}
500500

501-
if (fxls8974_get_active(dev, (enum fxls8974_active *)&regVal)) {
501+
if (fxls8974_get_active(dev, &regVal)) {
502502
LOG_ERR("Failed to set standby mode");
503503
return -EIO;
504504
}
@@ -560,7 +560,7 @@ static int fxls8974_init(const struct device *dev)
560560
return -EIO;
561561
}
562562

563-
if (fxls8974_get_active(dev, (enum fxls8974_active *)&regVal)) {
563+
if (fxls8974_get_active(dev, &regVal)) {
564564
LOG_ERR("Failed to get active mode");
565565
return -EIO;
566566
}

drivers/sensor/nxp/fxls8974/fxls8974.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,8 @@ struct fxls8974_data {
155155
#endif
156156
};
157157

158-
int fxls8974_get_active(const struct device *dev, enum fxls8974_active *active);
159-
int fxls8974_set_active(const struct device *dev, enum fxls8974_active active);
158+
int fxls8974_get_active(const struct device *dev, uint8_t *active);
159+
int fxls8974_set_active(const struct device *dev, uint8_t active);
160160

161161
#if DT_ANY_INST_ON_BUS_STATUS_OKAY(spi)
162162
int fxls8974_byte_write_spi(const struct device *dev,

0 commit comments

Comments
 (0)