Try/catch for modules?

Bernd Petrovitsch bernd at petrovitsch.priv.at
Fri Oct 18 12:04:58 EDT 2019


On 18/10/2019 17:43, Martin Galvan wrote:> El jue., 17 oct. 2019 a las 19:13, Valdis Klētnieks
> (<valdis.kletnieks at vt.edu>) escribió:
>>
>> For starters, the *correct* in-kernel way to deal with this is:
>>         if (!ptr) {
>>                 printk("You blew it!\n");
>>                 goto you_blew_it;
>>         }
> 
> goto statements are harmful. In any case, what I meant was to have
> some sort of safety net to prevent exceptions (i.e. if I screw up and
You actually want speed in the kernel and not necessarily extra effort
for "try" and "catch" which is - sooner or later - never really used.
And the "safety net" reduces the motivation to actually fix pointer bugs ....

> forget a NULL check) from panicking the system.
> 
>> Also, "current PID" and "my module" aren't two things that can correspond....
> 
> I don't understand what you mean by that. Module code (e.g. an ioctl)
> runs as some process. In the case of an ioctl, I'd assume it's the
A ioctl-handler runs in the context/on behalf/... of a process
(read: a user-space process/thread has called a syscall).

> same PID of the user process.
And there may be other code in your module which doesn't run
on behalf of a process/thread, e.g. triggered by a timer, hardware
IRQ, ...

So in general you don't have a "process" or "thread", only in some
situations....

MfG,
	Bernd
-- 
"I dislike type abstraction if it has no real reason. And saving
on typing is not a good reason - if your typing speed is the main
issue when you're coding, you're doing something seriously wrong."
    - Linus Torvalds
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pEpkey.asc
Type: application/pgp-keys
Size: 2472 bytes
Desc: not available
URL: <http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20191018/f15c8278/attachment.bin>


More information about the Kernelnewbies mailing list