Skip to content

Commit c12517e

Browse files
committed
hm0360: _set_pll(): guard against wide reads and silence unused-param warnings
* Mark all currently unused PLL parameters with (void) to remove -Wunused-parameter noise. * After a successful read_reg(), reject any value > 0xFF and return -ERANGE. Ensures only 8-bit data is written to PLL1CFG.
1 parent be37adc commit c12517e

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

sensors/hm0360.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <stdint.h>
77
#include <stdlib.h>
88
#include <string.h>
9+
#include <errno.h>
910
#include "sccb.h"
1011
#include "xclk.h"
1112
#include "hm0360.h"
@@ -345,6 +346,14 @@ static int set_xclk(sensor_t *sensor, int timer, int xclk)
345346

346347
static int _set_pll(sensor_t *sensor, int bypass, int multiplier, int sys_div, int root_2x, int pre_div, int seld5, int pclk_manual, int pclk_div)
347348
{
349+
(void)bypass;
350+
(void)multiplier;
351+
(void)sys_div;
352+
(void)root_2x;
353+
(void)pre_div;
354+
(void)seld5;
355+
(void)pclk_manual;
356+
(void)pclk_div;
348357
uint8_t value = 0;
349358
uint8_t pll_cfg = 0;
350359

@@ -362,6 +371,14 @@ static int _set_pll(sensor_t *sensor, int bypass, int multiplier, int sys_div, i
362371
if (ret < 0) {
363372
return ret;
364373
}
374+
if (ret > 0xFF) {
375+
/*
376+
* Guard against unexpected wide register values. If read_reg
377+
* ever returns a 16-bit result, reject values that don't fit
378+
* in a single byte to avoid truncation.
379+
*/
380+
return -ERANGE;
381+
}
365382

366383
pll_cfg = (uint8_t)ret;
367384
return write_reg(sensor->slv_addr, PLL1CFG, (pll_cfg & 0xFC) | value);

0 commit comments

Comments
 (0)