获取空指针的容器

问题描述 投票:0回答:1

我目前正在尝试摆脱以下功能所需的backref:

/**
 * amd_sfh_hid_poll - Updates the input report for a HID device.
 * @work:   The delayed work
 *
 * Polls input reports from the respective HID devices and submits
 * them by invoking hid_input_report() from hid-core.
 */
static void amd_sfh_hid_poll(struct work_struct *work)
{
    struct amd_sfh_hid_data *hid_data;
    struct hid_device *hid;
    size_t size;
    u8 *buf;

    hid_data = container_of(work, struct amd_sfh_hid_data, work.work);
    hid = hid_data->hid;
    size = get_descriptor_size(hid_data->sensor_idx, AMD_SFH_INPUT_REPORT);

    buf = kzalloc(size, GFP_KERNEL);
    if (!buf) {
        hid_err(hid, "Failed to allocate memory for input report!\n");
        goto reschedule;
    }

    size = get_input_report(hid_data->sensor_idx, 1, buf, size,
                            hid_data->cpu_addr);
    if (size < 0) {
        hid_err(hid, "Failed to get input report!\n");
        goto free_buf;
    }

    hid_input_report(hid, HID_INPUT_REPORT, buf, size, 0);

free_buf:
    kfree(buf);
reschedule:
    schedule_delayed_work(&hid_data->work, hid_data->interval);
}

struct amd_sfh_hid_data是分别存储在struct amd_sfh_hid_data下的驱动程序数据hid->driver_data。在工作队列中,我需要访问HID的驱动程序数据以及来自该HID设备的数据,我目前正在通过访问backref struct hid_device来进行访问。我现在尝试通过在驱动程序数据上使用struct hid_device来消除backref:

hid = hid_data->hid

但是,这也会导致页面错误

container_of

使用hid = container_of((void*)hid_data, struct hid_device, driver_data); 给定hid = container_of((void**)*hid_data, struct hid_device, driver_data); 成员的struct hid_device *的正确方法是什么?

c linux-kernel linux-device-driver
1个回答
0
投票

void *driver_data arg应该是来自container_of的成员的名称。您使用的member不是struct amd_sfh_hid_data的成员。

© www.soinside.com 2019 - 2024. All rights reserved.