From mboxrd@z Thu Jan 1 00:00:00 1970 From: hle@owl.eu.com (Hugo Lefeuvre) Date: Tue, 5 Jun 2018 21:48:23 -0400 Subject: develoment workflow: how to avoid duplicate work ? In-Reply-To: <20180605174713.GS14048@gavran.carpriv.carnet.hr> References: <20180531014432.GA3722@hle-laptop.local> <20180603192336.GV14048@gavran.carpriv.carnet.hr> <20180603222556.GB20060@hle-laptop.local> <20180604033303.GX14048@gavran.carpriv.carnet.hr> <12368.1528128607@turing-police.cc.vt.edu> <20180604223131.GA1981@hle-laptop.local> <68638.1528178148@turing-police.cc.vt.edu> <20180605142016.GA2334@hle-laptop.local> <179873.1528209201@turing-police.cc.vt.edu> <20180605174713.GS14048@gavran.carpriv.carnet.hr> Message-ID: <20180606014822.GA2933@hle-laptop.local> To: kernelnewbies@lists.kernelnewbies.org List-Id: kernelnewbies.lists.kernelnewbies.org > > It's not duplication, it's increment/decrement of a counter. > > > > Look for functions with 'get' and 'put' in their names. > > AFAICT counter is f_count in struct file, updated by fget and fput. Yes, this is the counter I was speaking about. But to me the only way to increment/decrement this counter was either to duplicate an existing reference using dup/dup2, or to fork the process. This was wrong, and I'm glad I learned that. FTR: After taking a look at the kernel code, the ioctl syscall is implemented in ksys_ioctl[0], which calls fdget/fdput to get the struct fd, incrementing and decrementing the count. Thanks your help ! > > I haven't looked at the code - there's an outside chance that the driver > > isn't doing reference counting correctly. > > pi433 driver does not mess with struct file too much so I guess it should > be safe :) I'll take a closer look at the TODO and come back later with a patch. If there's nothing to do I'll remove it, otherwise I'll fix it. Cheers, Hugo [0] https://elixir.bootlin.com/linux/latest/source/fs/ioctl.c#L692 -- Hugo Lefeuvre (hle) | www.owl.eu.com 4096/ 9C4F C8BF A4B0 8FC5 48EB 56B8 1962 765B B9A8 BACA