From: Christian König > Sent: 16 August 2017 09:32 > Am 16.08.2017 um 10:16 schrieb Jiri Pirko: > > Wed, Aug 16, 2017 at 09:49:07AM CEST, christian.koe...@amd.com wrote: > >> Am 16.08.2017 um 04:12 schrieb Chris Mi: ... > >>> - ret = idr_alloc(&bsg_minor_idr, bcd, 0, BSG_MAX_DEVS, GFP_KERNEL); > >>> - if (ret < 0) { > >>> + ret = idr_alloc(&bsg_minor_idr, bcd, &idr_index, 0, BSG_MAX_DEVS, > >>> + GFP_KERNEL); > >>> + if (ret) { > >>> if (ret == -ENOSPC) { > >>> printk(KERN_ERR "bsg: too many bsg devices\n"); > >>> ret = -EINVAL; > >> The condition "if (ret)" will now always be true after the first allocation > >> and so we always run into the error handling after that. > > On success, idr_alloc returns 0. > > Ah, I see. You change the idr_alloc to return the resulting index as > separate parameter.
Returning values by reference typically generates considerably worse code that using the function return value. It isn't just the extra parameter, it can constrain the generated code in other ways. That is why ERR_PTR() and friends exist. IMHO You need a really good reason to make this change. David