modbus: fix potential null pointer dereference
modbus: fix potential null pointer dereference

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

Signed-off-by: Jacob Siverskog <f862f167b85d41b225785c70d70808bc7337c1fe@teenage.engineering>

zephyrproject-rtos/zephyr,zephyrproject-rtos/zephyr,galak/zephyr,nashif/zephyr,finikorg/zephyr,galak/zephyr,galak/zephyr,Vudentz/zephyr,galak/zephyr,finikorg/zephyr,Vudentz/zephyr,finikorg/zephyr,zephyrproject-rtos/zephyr,finikorg/zephyr,nashif/zephyr,finikorg/zephyr,nashif/zephyr,Vudentz/zephyr,nashif/zephyr,Vudentz/zephyr,nashif/zephyr,zephyrproject-rtos/zephyr,zephyrproject-rtos/zephyr,Vudentz/zephyr,galak/zephyr,Vudentz/zephyr