Commit 2954dcf4 authored by Jacob Siverskog's avatar Jacob Siverskog Committed by Jukka Rissanen
Browse files

modbus: fix potential null pointer dereference



reorganize code so that null pointer check is done prior to accessing
element.

Signed-off-by: default avatarJacob Siverskog <jacob@teenage.engineering>
parent a9b4cae0
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -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)) {