Skip to content

Commit e437e90

Browse files
committed
misc: rp1-pio: Add narrowing casts
Avoid some compiler warnings by adding explicit narrowing casts. See: #7309 Signed-off-by: Phil Elwell <phil@raspberrypi.com>
1 parent eb7cf94 commit e437e90

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

include/linux/pio_rp1.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#define NUM_PIO_STATE_MACHINES 4
4343
#define PIO_INSTRUCTION_COUNT 32
4444
#define PIO_ORIGIN_ANY ((uint)(~0))
45+
#define PIO_ORIGIN_INVALID ((uint)(~0))
4546
#define GPIOS_MASK ((1 << RP1_PIO_GPIO_COUNT) - 1)
4647

4748
#define PICO_NO_HARDWARE 0
@@ -280,7 +281,7 @@ static inline bool pio_can_add_program(struct rp1_pio_client *client,
280281

281282
if (bad_params_if(client, program->length > PIO_INSTRUCTION_COUNT))
282283
return false;
283-
args.origin = (program->origin == -1) ? PIO_ORIGIN_ANY : program->origin;
284+
args.origin = (uint16_t)((program->origin == -1) ? PIO_ORIGIN_ANY : program->origin);
284285
args.num_instrs = program->length;
285286

286287
memcpy(args.instrs, program->instructions, args.num_instrs * sizeof(args.instrs[0]));
@@ -295,7 +296,7 @@ static inline bool pio_can_add_program_at_offset(struct rp1_pio_client *client,
295296
if (bad_params_if(client, program->length > PIO_INSTRUCTION_COUNT ||
296297
offset >= PIO_INSTRUCTION_COUNT))
297298
return false;
298-
args.origin = offset;
299+
args.origin = (uint16_t)offset;
299300
args.num_instrs = program->length;
300301

301302
memcpy(args.instrs, program->instructions, args.num_instrs * sizeof(args.instrs[0]));
@@ -308,13 +309,13 @@ static inline uint pio_add_program(struct rp1_pio_client *client, const pio_prog
308309
int offset;
309310

310311
if (bad_params_if(client, program->length > PIO_INSTRUCTION_COUNT))
311-
return PIO_ORIGIN_ANY;
312-
args.origin = (program->origin == -1) ? PIO_ORIGIN_ANY : program->origin;
312+
return PIO_ORIGIN_INVALID;
313+
args.origin = (uint16_t)((program->origin == -1) ? PIO_ORIGIN_ANY : program->origin);
313314
args.num_instrs = program->length;
314315

315316
memcpy(args.instrs, program->instructions, args.num_instrs * sizeof(args.instrs[0]));
316317
offset = rp1_pio_add_program(client, &args);
317-
return (offset >= 0) ? offset : PIO_ORIGIN_ANY;
318+
return (offset >= 0) ? offset : PIO_ORIGIN_INVALID;
318319
}
319320

320321
static inline int pio_add_program_at_offset(struct rp1_pio_client *client,
@@ -325,7 +326,7 @@ static inline int pio_add_program_at_offset(struct rp1_pio_client *client,
325326
if (bad_params_if(client, program->length > PIO_INSTRUCTION_COUNT ||
326327
offset >= PIO_INSTRUCTION_COUNT))
327328
return -EINVAL;
328-
args.origin = offset;
329+
args.origin = (uint16_t)offset;
329330
args.num_instrs = program->length;
330331

331332
memcpy(args.instrs, program->instructions, args.num_instrs * sizeof(args.instrs[0]));
@@ -337,7 +338,7 @@ static inline int pio_remove_program(struct rp1_pio_client *client, const pio_pr
337338
{
338339
struct rp1_pio_remove_program_args args;
339340

340-
args.origin = loaded_offset;
341+
args.origin = (uint16_t)loaded_offset;
341342
args.num_instrs = program->length;
342343

343344
return rp1_pio_remove_program(client, &args);

0 commit comments

Comments
 (0)