lkml.org 
[lkml]   [2023]   [Aug]   [9]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
SubjectRe: [PATCH v6 3/4] iommufd: Add IOMMU_GET_HW_INFO
From
On 2023/8/10 0:16, Jason Gunthorpe wrote:
> On Wed, Aug 09, 2023 at 06:16:19PM +0800, Baolu Lu wrote:
>> On 2023/8/8 23:35, Yi Liu wrote:
>>> +static int iommufd_fill_hw_info(struct device *dev, void __user *user_ptr,
>>> + unsigned int *length, u32 *type)
>>> +{
>>> + const struct iommu_ops *ops;
>>> + unsigned int data_len;
>>> + void *data;
>>> + int rc = 0;
>>> +
>>> + ops = dev_iommu_ops(dev);
>>> + if (!ops->hw_info) {
>>> + *length = 0;
>>> + *type = IOMMU_HW_INFO_TYPE_NONE;
>>> + return 0;
>>> + }
>>> +
>>> + data = ops->hw_info(dev, &data_len, type);
>>> + if (IS_ERR(data))
>>> + return PTR_ERR(data);
>>> +
>>> + /*
>>> + * drivers that have hw_info callback should have a unique
>>> + * iommu_hw_info_type.
>>> + */
>>> + if (WARN_ON_ONCE(*type == IOMMU_HW_INFO_TYPE_NONE)) {
>>> + rc = -ENODEV;
>>> + goto err_free;
>>> + }
>>> +
>>> + *length = min(*length, data_len);
>>> + if (copy_to_user(user_ptr, data, *length)) {
>> copy_to_user() returns the number of bytes that were successfully
>> copied, right?
> It returns length on failure and 0 on success

Then it's fine. Thanks for the explanation.

Best regards,
baolu

\
 
 \ /
  Last update: 2023-08-10 04:07    [W:0.044 / U:0.184 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site