[go: up one dir, main page]

|
|
Log in / Subscribe / Register

The case of the prematurely freed SKB

The case of the prematurely freed SKB

Posted Mar 2, 2017 9:29 UTC (Thu) by oshepherd (guest, #90163)
Parent article: The case of the prematurely freed SKB

I realise that it's a convention now and probably impossible and more dangerous to change, but... I can't help but feel _get and _put postfixes for increasing and decreasing the reference count are truly atrocious naming.

AddRef/DecRef, Retain/Release. There are just so many better options for naming ref counting functions. Bonus points if your AddRef/Retain function returns a pointer to the object you're increasing the ref count on, so you can do it while assigning...


to post comments

The case of the prematurely freed SKB

Posted Mar 2, 2017 21:32 UTC (Thu) by neilbrown (subscriber, #359) [Link] (5 responses)

"Retain" and "AddRef" are each 6 characters. "get" is 3 characters.
"get" wins easily.

I agree that having "get" return the pointer is a win.

The case of the prematurely freed SKB

Posted Mar 3, 2017 8:47 UTC (Fri) by oshepherd (guest, #90163) [Link]

A 3 character length increase doesn't bother me compared to the overhead of thinking "skbuf_get? get what?"

The case of the prematurely freed SKB

Posted Mar 3, 2017 13:14 UTC (Fri) by mathstuf (subscriber, #69389) [Link]

What about inc and dec?

The case of the prematurely freed SKB

Posted Mar 3, 2017 18:18 UTC (Fri) by marcH (subscriber, #57642) [Link] (2 responses)

> "Retain" and "AddRef" are each 6 characters. "get" is 3 characters. "get" wins easily.

Are you being serious? Granted: https://martinfowler.com/bliki/TwoHardThings.html

but... 3 characters winning over 6, really?

The case of the prematurely freed SKB

Posted Mar 3, 2017 21:29 UTC (Fri) by neilbrown (subscriber, #359) [Link] (1 responses)

> but... 3 characters winning over 6, really?

Yes, really. These things are used a lot. Common words tend to be shorter than uncommon word, and for good reason. Less wasted space for example.
It doesn't really matter what the letters are as long as they are used consistently.
If you made a convention that "thing_foo" incremented the ref count and returned the pointer, and "thing_bar" decremented the refcount and discarded when it became zero, then we would all add "_foo" and "_bar" to our language fairly quickly and there would be no confusion.
I could argue that would be better than the current situation where we mostly use "get" and "put", but they don't always mean quite the same thing.

When new people come to the code and see "get" and "put" it might seem like it makes it easy for them. But it can just as easily lead them to think they understand something that they don't. Using more letters might just give them more confidence that the meaning of the word is "obvious", which is probably isn't.

The case of the prematurely freed SKB

Posted Mar 3, 2017 21:46 UTC (Fri) by marcH (subscriber, #57642) [Link]

Then it hurts me to say this but you want acronyms. They're short AND sure not to be too tainted by plain English preconceptions.

(It hurts me because I live in a world of massive abuse of acronyms)

The case of the prematurely freed SKB

Posted Mar 6, 2017 12:41 UTC (Mon) by robbe (guest, #16131) [Link] (1 responses)

You did not state *why* you think get/put is that bad. What would someone unfamiliar with the kernel conventions think these functions do?

The case of the prematurely freed SKB

Posted Mar 6, 2017 23:13 UTC (Mon) by mathstuf (subscriber, #69389) [Link]

One could think of it as getting or putting a count into the counter rather than getting a reference and the returning it. I had the same problem for the longest time with the power symbol. I saw it as 0 for a closed circuit and 1 for an open circuit. Exactly backwards.

The case of the prematurely freed SKB

Posted Mar 9, 2017 13:27 UTC (Thu) by bcopeland (subscriber, #51750) [Link]

> I realise that it's a convention now and probably impossible and more dangerous to change, but... I can't help but feel _get and _put postfixes for increasing and decreasing the reference count are truly atrocious naming.

My understanding is that this convention goes way back. At least 6th edition UNIX used iget() and iput() to maintain reference counts (e.g. see p.85 in http://www.lemis.com/grog/Documentation/Lions/book.pdf). So it not only (probably) predates people using "retain" as the verb here, but it also predates Linux.


Copyright © 2026, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds