modbus: fix potential null pointer dereference
reorganize code so that null pointer check is done prior to accessing element. Signed-off-by: Jacob Siverskog <jacob@teenage.engineering>
This commit is contained in:
parent
a9b4cae019
commit
2954dcf4ed
1 changed files with 3 additions and 1 deletions
|
@ -404,13 +404,15 @@ static void cb_handler_tx(struct modbus_context *ctx)
|
|||
static void uart_cb_handler(const struct device *dev, void *app_data)
|
||||
{
|
||||
struct modbus_context *ctx = (struct modbus_context *)app_data;
|
||||
struct modbus_serial_config *cfg = ctx->cfg;
|
||||
struct modbus_serial_config *cfg;
|
||||
|
||||
if (ctx == NULL) {
|
||||
LOG_ERR("Modbus hardware is not properly initialized");
|
||||
return;
|
||||
}
|
||||
|
||||
cfg = ctx->cfg;
|
||||
|
||||
while (uart_irq_update(cfg->dev) && uart_irq_is_pending(cfg->dev)) {
|
||||
|
||||
if (uart_irq_rx_ready(cfg->dev)) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue