mcp251xfd-dump: fail if no registers can be read from regmap file

This commit is contained in:
Marc Kleine-Budde
2023-01-03 15:46:07 +01:00
parent aadf98b49b
commit 088176e4e0
+15 -4
View File
@@ -2,7 +2,7 @@
//
// Microchip MCP251xFD Family CAN controller debug tool
//
// Copyright (c) 2020 Pengutronix,
// Copyright (c) 2020, 2022 Pengutronix,
// Marc Kleine-Budde <kernel@pengutronix.de>
//
@@ -26,21 +26,32 @@ do_mcp251xfd_regmap_read(struct mcp251xfd_priv *priv,
FILE *reg_file;
uint16_t reg;
uint32_t val;
unsigned int n = 0;
int err = 0;
reg_file = fopen(file_path, "r");
if (!reg_file)
return -errno;
while (fscanf(reg_file, "%hx: %x\n", &reg, &val) == 2) {
if (reg >= ARRAY_SIZE(mem->buf))
return -EINVAL;
if (reg >= ARRAY_SIZE(mem->buf)) {
err = -EINVAL;
goto out_close;
}
*(uint32_t *)(mem->buf + reg) = val;
n++;
}
printf("regmap: Found %u registers in %s\n", n, file_path);
if (!n)
err = -EINVAL;
out_close:
fclose(reg_file);
return 0;
return err;
}
int mcp251xfd_regmap_read(struct mcp251xfd_priv *priv,