Skip to content

Commit 19b3638

Browse files
jgunthorpegregkh
authored andcommitted
RDMA/uverbs: Use an unambiguous errno for method not supported
[ Upstream commit 3624a8f ] Returning EOPNOTSUPP is problematic because it can also be returned by the method function, and we use it in quite a few places in drivers these days. Instead, dedicate EPROTONOSUPPORT to indicate that the ioctl framework is enabled but the requested object and method are not supported by the kernel. No other case will return this code, and it lets userspace know to fall back to write(). grep says we do not use it today in drivers/infiniband subsystem. Signed-off-by: Jason Gunthorpe <[email protected]> Reviewed-by: Matan Barak <[email protected]> Signed-off-by: Doug Ledford <[email protected]> Signed-off-by: Sasha Levin <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 827aab4 commit 19b3638

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

drivers/infiniband/core/uverbs_ioctl.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -245,16 +245,13 @@ static long ib_uverbs_cmd_verbs(struct ib_device *ib_dev,
245245
uintptr_t data[UVERBS_OPTIMIZE_USING_STACK_SZ / sizeof(uintptr_t)];
246246
#endif
247247

248-
if (hdr->reserved)
249-
return -EINVAL;
250-
251248
object_spec = uverbs_get_object(ib_dev, hdr->object_id);
252249
if (!object_spec)
253-
return -EOPNOTSUPP;
250+
return -EPROTONOSUPPORT;
254251

255252
method_spec = uverbs_get_method(object_spec, hdr->method_id);
256253
if (!method_spec)
257-
return -EOPNOTSUPP;
254+
return -EPROTONOSUPPORT;
258255

259256
if ((method_spec->flags & UVERBS_ACTION_FLAG_CREATE_ROOT) ^ !file->ucontext)
260257
return -EINVAL;
@@ -310,6 +307,16 @@ static long ib_uverbs_cmd_verbs(struct ib_device *ib_dev,
310307

311308
err = uverbs_handle_method(buf, ctx->uattrs, hdr->num_attrs, ib_dev,
312309
file, method_spec, ctx->uverbs_attr_bundle);
310+
311+
/*
312+
* EPROTONOSUPPORT is ONLY to be returned if the ioctl framework can
313+
* not invoke the method because the request is not supported. No
314+
* other cases should return this code.
315+
*/
316+
if (unlikely(err == -EPROTONOSUPPORT)) {
317+
WARN_ON_ONCE(err == -EPROTONOSUPPORT);
318+
err = -EINVAL;
319+
}
313320
out:
314321
#ifdef UVERBS_OPTIMIZE_USING_STACK_SZ
315322
if (ctx_size > UVERBS_OPTIMIZE_USING_STACK_SZ)
@@ -348,7 +355,7 @@ long ib_uverbs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
348355
}
349356

350357
if (hdr.reserved) {
351-
err = -EOPNOTSUPP;
358+
err = -EPROTONOSUPPORT;
352359
goto out;
353360
}
354361

0 commit comments

Comments
 (0)