I'm developing a shell module for the sensor drivers and I want to validate if the device name passed from the user is a sensor device.
The userspace infrastructure has facilities for this, but as I commented in your patch, what you are doing is only intended for system call handlers. The Zephyr kernel running in supervisor mode is intended to be very lightweight and doesn't have features like this, it's a garbage-in-garbage-out type of situation.
The proper way to do this is have the shell main loop run in user mode, it's the only way to make robust assertions that malformed user input can't hose the system. I suggest just dropping the checks.