From bc4ba9070c68a3c3d686c8d28a3f07b83f656d99 Mon Sep 17 00:00:00 2001 From: Pratim Ugale Date: Sat, 24 Aug 2019 08:21:33 +0000 Subject: [PATCH] Fix bug in prussd.py that causes kernel oops while sending message through rpmsg channel A kernel oops (NULL pointer dereference) was thrown when the pruss_api driver hadn't already been probed because there was no check that the rpmsg device file in /dev was being created before sending messages to the PRU. Sometimes the oops wasn't thrown but there was a loss of some initial data sent to PRU before the rpmsg device file gets initialized. Now, the code waits before sending messages to PRU until the appropriate device file is created to ensure no loss of data. No kernel oops is thrown now. The device file creation is timed out after 3 seconds otherwise the function might get stuck in an infinite loop if rpmsg isn't being used and function gets called. --- prussd/prussd.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/prussd/prussd.py b/prussd/prussd.py index 97b7eab..6387928 100755 --- a/prussd/prussd.py +++ b/prussd/prussd.py @@ -20,6 +20,7 @@ import threading import mmap # For memory functions import struct # For memory functions +import time PRU_ICSS = 0x4a300000 # This is the address of the PRU Subsystem on the RAM PRU_ICSS_SIZE = 512*1024 # This is the length of the PRU subsystem ie it is of 512 K @@ -168,8 +169,15 @@ def send_msg(cmd): rpmsg_dev = rpmsg_devnode(chan_name, chan_port) if chan_name not in paths.RPMSG_CHANNELS: return -errno.EPERM - if not os.path.exists(rpmsg_dev): - return -errno.ENODEV + + time_to_wait = 3 + time_counter = 0 + + while not os.path.exists(rpmsg_dev): + time.sleep(1) + time_counter += 1 + if (time_counter >= time_to_wait): + return -errno.ENODEV if mode == 's': try: