News for hackers. Stuff that matters.
Re:Sony publishes an official Linux driver for Playstation 5... by iso8859-1 on Thursday December 24, 2020 @06:15PM (#25532459)
Good to see they are still using GOTO. Straight-forward and performant.
Re:Sony publishes an official Linux driver for Playstation 5... by pizza234 on Friday December 25, 2020 @05:43AM (#25535670)
I spent to some time to check and analyze the code.

The author uses it in a clear pattern, specifically, as a sibiling post mentions, in order to achieve error handling (additionally, with fall-through); the labels are indeed neatly placed at the end of the function, after the `ret` exit.

The problem is consistency - the upper half of that function performs error handling without goto, and the lower half with it.

I personally prefer all-or-none solutions, since I highly value consistency, but on the other hand, I do consider this solution acceptable, since it still has a tidy (enough) structure.

Re:Sony publishes an official Linux driver for Playstation 5... by centimeter on Thursday December 24, 2020 @07:04PM (#25532868)
Goto doesn't have a performance benefit over other control flow structures with a modern compiler.
Re:Sony publishes an official Linux driver for Playstation 5... by the_duke on Thursday December 24, 2020 @09:05PM (#25533549)
In C GOTO is often by far the cleanest solution for error handling.

Everything else turns into an ugly, unreadable mess in functions that need to free resources or do some kind of cleanup.

Re:Sony publishes an official Linux driver for Playstation 5... by Uptrenda on Friday December 25, 2020 @04:17AM (#25535313)
I've seen the goto error-handling approach used now in SDKs written by developers from companies like Microsoft, Nvidia, and Nordic Semiconductor. It really does seem to be the best way to do it. And it's simple. Mess something up... goto cleanup... Seems fine to me!
Re:Sony publishes an official Linux driver for Playstation 5... by centimeter on Saturday December 26, 2020 @04:44PM (#25546674)
My comment has nothing to do with error handling. I was addressing a false claim about performance.
Re:Sony publishes an official Linux driver for Playstation 5... by akira2501 on Thursday December 24, 2020 @07:10PM (#25532896)
Yes, but it does reduce the level of indentation required in most functions that use it. That consideration is part of the kernel style guidelines.
Re:Sony publishes an official Linux driver for Playstation 5... by eloff on Thursday December 24, 2020 @09:20PM (#25533616)
In system C code its usually used for error and retry logic to make the code more readable. It's rarely ever used for performance.
Re:Sony publishes an official Linux driver for Playstation 5... by asddubs on Thursday December 24, 2020 @09:06PM (#25533554)
that's definitely not categorically true
Re:Sony publishes an official Linux driver for Playstation 5... by mhh__ on Thursday December 24, 2020 @11:06PM (#25534107)
Can you think of a counterexample? I wouldn't be surprised if you could trick a compiler with a goto but optimizing control flow is very much the type of optimization that Knuth was referring to. Now that almost all compilers use SSA I'd be surprised if it was the case outside of fairly deep control flow
Re:Sony publishes an official Linux driver for Playstation 5... by Out_of_Characte on Friday December 25, 2020 @05:43AM (#25535669)
Error handling was already mentioned ITT. Goto use seems like a litmus test for bad programming. The presence of it doesn't prove bad programmings but lots of goto statements could be reasonably be expected to be replaced with safer switch statements. Extremely nested functions are another area that is best served with a goto. Breaking out of many functions has performance implications I believe.
Re:Sony publishes an official Linux driver for Playstation 5... by viraptor on Friday December 25, 2020 @07:03AM (#25535989)
The question was about performance, not necessarily other aspects.
Re:Sony publishes an official Linux driver for Playstation 5... by anonunivgrad on Thursday December 24, 2020 @07:51PM (#25533146)
If you’re criticizing goto in kernel source, you don’t know what you’re talking about. It’s incredible how many people just regurgitate this anti-goto meme without any experience writing system C code. There are various highly structured uses of goto used for systems programming in C, most prominently for error handling but also for things like retry logic.
Re:Sony publishes an official Linux driver for Playstation 5... by gregoryl on Thursday December 24, 2020 @08:04PM (#25533224)
You built a strawman and burnt it down!
Re:Sony publishes an official Linux driver for Playstation 5... by eloff on Thursday December 24, 2020 @09:21PM (#25533619)
Yes, you're right.
Re:Sony publishes an official Linux driver for Playstation 5... by will4274 on Thursday December 24, 2020 @06:36PM (#25532648)
I checked (just for you). All four gotos are reasonable forward gotos and not what the article "goto considered harmful" was referring to. As an aside, why did you write goto in all caps in your comment? While your comment was quite basic, it wasn't BASIC, so no such caps are required. Please don't shout.