On Tue, Sep 08, 2015 at 04:30:52AM +0300, Dmitry V. Levin wrote:
> On Tue, Sep 08, 2015 at 04:18:11AM +0300, Dmitry V. Levin wrote:
> [...]
> > So the whole function should look smth like this:
> > 
> > static int i915_getparam(struct tcb *tcp, const unsigned int code, long arg)
> > {
> >     struct drm_i915_getparam param;
> > 
> >     if (entering(tcp)) {
> >             if (umove_or_printaddr(tcp, arg, &param))
> >                     return RVAL_DECODED | 1;
> >             tprints(", {param=");
> 
> or rather
>               tprints(", ");
>               if (umove_or_printaddr(tcp, arg, &param))
>                       return RVAL_DECODED | 1;
>               tprints("{param=");

or rather

static int
i915_getparam(struct tcb *tcp, const unsigned int code, const long arg)
{
        struct drm_i915_getparam param;
        int value;

        if (entering(tcp)) {
                tprints(", ");
                if (umove_or_printaddr(tcp, arg, &param))
                        return RVAL_DECODED | 1;
                tprints("{param=");
                printxval(drm_i915_getparams, param.param, "I915_PARAM_???");
                return 0;
        }

        if (!umove(tcp, arg, &param)) {
                tprints(", value=");
                if (!umove_or_printaddr(tcp, (long) param.value, &value)) {
                        switch (param.param) {
                        case I915_PARAM_CHIPSET_ID:
                                tprintf("[%#04x]", value);
                                break;
                        default:
                                tprintf("[%d]", value);
                        }
                }
        }
        tprints("}");
        return 1;
}

Note that those structure members that are set by the kernel on exiting
syscall shouldn't normally be printed in case of syserror(tcp).

In case of i915_getparam, no extra check is needed because param.value is
an address supplied by userspace and umove_or_printaddr already performs
all necessary checks, but in other IOWR parsers you might want to use
        if (!syserror(tcp) && !umove(tcp, arg, &param)) {
instead.


-- 
ldv

Attachment: pgp9B2ipYt45y.pgp
Description: PGP signature

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

Reply via email to