Re: [PATCH v4] HID: New hid-cp2112 driver
From: Oliver Neukum
Date: Thu Jan 30 2014 - 04:17:34 EST
On Wed, 2014-01-29 at 15:46 -0800, Joe Perches wrote:
> > +static int cp2112_hid_get(struct hid_device *hdev, unsigned char report_number,
> > + u8 *data, size_t count, unsigned char report_type)
> > +{
> > + u8 *buf;
> > + int ret;
> > +
> > + buf = kmalloc(count, GFP_KERNEL);
> > + if (!buf)
> > + return -ENOMEM;
> > +
> > + ret = hdev->hid_get_raw_report(hdev, report_number, buf, count,
> > + report_type);
> > + memcpy(data, buf, count);
> > + kfree(buf);
> > + return ret;
>
> if the data is going to be copied in data,
> why not just use data in hid_get_raw_report
> and avoid the malloc?
He must not. It would violate the DMA rules. This function is passed
pointers to parts of structures. Access to the structures may race
with a DMA to/from the buffer. That violates the DMA rules.
Regards
Oliver
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/