RE: [patch net-next 0/3] net/sched: Improve getting objects by indexes

From
David Laight <hidden>
Date
2017-08-16 14:28:54
Reply to
Christian König, 2017-08-16
From: Christian König
Sent: 16 August 2017 09:32
Am 16.08.2017 um 10:16 schrieb Jiri Pirko:
quoted
Wed, Aug 16, 2017 at 09:49:07AM CEST, christian.koenig@amd.com wrote:
quoted
Am 16.08.2017 um 04:12 schrieb Chris Mi:
...
quoted
quoted
quoted
-	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

Thread (16 messages) 16 messages, 7 authors, last reply 2017-08-16
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help