[PATCH 1/3] tfi: The tfi_alloc doesn't allocate anything, rename the function

Holger Hans Peter Freyther hfreyther at sysmocom.de
Sun Aug 25 11:55:08 UTC 2013

On Sun, Aug 25, 2013 at 01:01:34PM +0200, Holger Hans Peter Freyther wrote:


> Call things by what they do and this function doesn't allocate
> anything but it is searching for the first unallocated tbf index.

as part of cleaning up and adding structure (and on the way to
eliminate the various hidden errors) I came across tfi_alloc. There
are three places that mostly do (the topic of copy and paste in the
pcu code is another topic):

	tfi = tfi_alloc()
	if (tfi < 0)
	tbf = tbf_alloc(tfi,...);
	if (!tbf)

Now just by the name... we would leak the result of tfi_alloc in the
above code. But then again tfi_alloc doesn't allocate anything it is
just trying to find an unallocated index.

Which brings me to:
Name things by what they do (and update the name when the implementation
does change). In the above case if the method is called tfi_find_free
I will know that there is no side-effect and that I will not need to
call a tfi_free.


- Holger Freyther <hfreyther at sysmocom.de>       http://www.sysmocom.de/
* sysmocom - systems for mobile communications GmbH
* Schivelbeiner Str. 5
* 10439 Berlin, Germany
* Sitz / Registered office: Berlin, HRB 134158 B
* Geschaeftsfuehrer / Managing Directors: Holger Freyther, Harald Welte

More information about the osmocom-net-gprs mailing list