mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-10-29 23:53:32 +00:00
can: mcp251xfd: ring: mcp251xfd_ring_init(): checked RAM usage of ring setup
With this patch the usage of the on-chip RAM is checked. In the current driver the FIFO setup is fixed and always fits into the RAM. With an upcoming patch series the ring and FIFO setup will be more dynamic. Although using more RAM than available should not happen, but add this safety check, just in case. Link: https://lore.kernel.org/all/20220217103826.2299157-6-mkl@pengutronix.de Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
This commit is contained in:
parent
62713f0d9a
commit
fa0b68df7c
3 changed files with 16 additions and 4 deletions
|
@ -760,7 +760,9 @@ static int mcp251xfd_chip_start(struct mcp251xfd_priv *priv)
|
|||
if (err)
|
||||
goto out_chip_stop;
|
||||
|
||||
mcp251xfd_ring_init(priv);
|
||||
err = mcp251xfd_ring_init(priv);
|
||||
if (err)
|
||||
goto out_chip_stop;
|
||||
|
||||
err = mcp251xfd_chip_fifo_init(priv);
|
||||
if (err)
|
||||
|
|
|
@ -207,9 +207,9 @@ mcp251xfd_ring_init_rx(struct mcp251xfd_priv *priv, u16 *base, u8 *fifo_nr)
|
|||
}
|
||||
}
|
||||
|
||||
void mcp251xfd_ring_init(struct mcp251xfd_priv *priv)
|
||||
int mcp251xfd_ring_init(struct mcp251xfd_priv *priv)
|
||||
{
|
||||
u16 base = 0;
|
||||
u16 base = 0, ram_used;
|
||||
u8 fifo_nr = 1;
|
||||
|
||||
netdev_reset_queue(priv->ndev);
|
||||
|
@ -217,6 +217,16 @@ void mcp251xfd_ring_init(struct mcp251xfd_priv *priv)
|
|||
mcp251xfd_ring_init_tef(priv, &base);
|
||||
mcp251xfd_ring_init_rx(priv, &base, &fifo_nr);
|
||||
mcp251xfd_ring_init_tx(priv, &base, &fifo_nr);
|
||||
|
||||
ram_used = base - MCP251XFD_RAM_START;
|
||||
if (ram_used > MCP251XFD_RAM_SIZE) {
|
||||
netdev_err(priv->ndev,
|
||||
"Error during ring configuration, using more RAM (%u bytes) than available (%u bytes).\n",
|
||||
ram_used, MCP251XFD_RAM_SIZE);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void mcp251xfd_ring_free(struct mcp251xfd_priv *priv)
|
||||
|
|
|
@ -882,7 +882,7 @@ u16 mcp251xfd_crc16_compute2(const void *cmd, size_t cmd_size,
|
|||
const void *data, size_t data_size);
|
||||
u16 mcp251xfd_crc16_compute(const void *data, size_t data_size);
|
||||
int mcp251xfd_regmap_init(struct mcp251xfd_priv *priv);
|
||||
void mcp251xfd_ring_init(struct mcp251xfd_priv *priv);
|
||||
int mcp251xfd_ring_init(struct mcp251xfd_priv *priv);
|
||||
void mcp251xfd_ring_free(struct mcp251xfd_priv *priv);
|
||||
int mcp251xfd_ring_alloc(struct mcp251xfd_priv *priv);
|
||||
int mcp251xfd_handle_rxif(struct mcp251xfd_priv *priv);
|
||||
|
|
Loading…
Reference in a new issue