canopen: CO_driver: Fix Coverity issues (NULL deref, dead code)

There were two dereference after NULL check and logical dead code.

Fixes #22434
Fixes #22443
Fixes #22435
Coverity-CID: 207978
Coverity-CID: 207977
Coverity-CID: 207964

Signed-off-by: Alexander Wachter <alexander@wachter.cloud>
diff --git a/subsys/canbus/canopen/CO_driver.c b/subsys/canbus/canopen/CO_driver.c
index ecc36a4..7a101cb 100644
--- a/subsys/canbus/canopen/CO_driver.c
+++ b/subsys/canbus/canopen/CO_driver.c
@@ -253,7 +253,11 @@
 	struct zcan_filter filter;
 	CO_CANrx_t *buffer;
 
-	if (!CANmodule || !pFunct || (index >= CANmodule->rx_size)) {
+	if (CANmodule == NULL) {
+		return CO_ERROR_ILLEGAL_ARGUMENT;
+	}
+
+	if (!pFunct || (index >= CANmodule->rx_size)) {
 		LOG_ERR("failed to initialize CAN rx buffer, illegal argument");
 		CO_errorReport(CANmodule->em, CO_EM_GENERIC_SOFTWARE_ERROR,
 			       CO_EMC_SOFTWARE_INTERNAL, 0);
@@ -293,7 +297,11 @@
 {
 	CO_CANtx_t *buffer;
 
-	if (!CANmodule || (index >= CANmodule->tx_size)) {
+	if (CANmodule == NULL) {
+		return NULL;
+	}
+
+	if (index >= CANmodule->tx_size) {
 		LOG_ERR("failed to initialize CAN rx buffer, illegal argument");
 		CO_errorReport(CANmodule->em, CO_EM_GENERIC_SOFTWARE_ERROR,
 			       CO_EMC_SOFTWARE_INTERNAL, 0);
@@ -447,7 +455,8 @@
 			}
 		}
 
-		if (rx_overflows != 0U) {
+		/* This code can be activated if we can read the overflows*/
+		if (false && rx_overflows != 0U) {
 			CO_errorReport(em, CO_EM_CAN_RXB_OVERFLOW,
 				       CO_EMC_CAN_OVERRUN, errors);
 		}