Re: [PATCH 03/10] RDMA: Add ib_respond_udata()

Leon Romanovsky
2026-02-17T07:48:38Z

On Mon, Feb 16, 2026 at 07:14:24PM -0400, Jason Gunthorpe wrote:
> On Fri, Feb 13, 2026 at 11:48:13AM -0400, Jason Gunthorpe wrote:
> > On Fri, Feb 13, 2026 at 05:37:39PM +0200, Leon Romanovsky wrote:
> > > On Fri, Feb 13, 2026 at 08:43:59AM -0400, Jason Gunthorpe wrote:
> > > > On Fri, Feb 13, 2026 at 12:10:53PM +0200, Leon Romanovsky wrote:
> > > > > > @@ -3177,6 +3177,38 @@ static inline int _ib_copy_validate_udata_in(struct ib_udata *udata, void *req,
> > > > > > ret; \
> > > > > > })
> > > > > >
> > > > > > +static inline int _ib_respond_udata(struct ib_udata *udata, const void *src,
> > > > > > + size_t len)
> > > > > > +{
> > > > > > + size_t copy_len;
> > > > > > +
> > > > > > + copy_len = min(len, udata->outlen);
> > > > >
> > > > > Don't you need to check that udata->outlen is larger than zero?
> > > >
> > > > As far as I can tell 0 works fine with copy_to_user()
> > >
> > > My main concern that it is not clear what return value will be in that
> > > case.
> > >
> > > + copy_len = min(len, udata->outlen);
> > > + if (copy_to_user(udata->outbuf, src, copy_len))
> > > + return -EFAULT; <--- this?
> > > + if (copy_len < udata->outlen) {
> > > ...
> > > + }
> > > + return 0; <- or this?
> >
> > Oh, yeah, that's a really good point.
>
> So it still returns 0, copy_to_user() returns the number of bytes left
> to copy. See Documentation/kernel-hacking/hacking.rst
>
> Unlike :c:func:`put_user()` and :c:func:`get_user()`, they
> return the amount of uncopied data (ie. 0 still means success).
>
> Number of bytes left to copy for a 0 length copy is still 0, not
> EFAULT.
>
> I'm just going to add a comment.

It should work as well.

Thanks

>
> Jason
>