为什么我的内核模块会抛出“断线"?尝试写入设备时出现错误? [英] Why is my kernel module throwing "broken pipe" errors when I try to write to a device?

查看:122
本文介绍了为什么我的内核模块会抛出“断线"?尝试写入设备时出现错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在用C编写Linux内核模块.该模块为USB灯(该设备由三个彩色LED组成)提供了非常基本的驱动程序.我设法使驱动程序可以毫无问题地加载和卸载,还可以创建设备(/dev/wn0/dev/wn1等).但是,尝试写入设备时,我总是收到错误消息:

I am currently in the process of writing a Linux kernel module in C. The module provides an extremely basic driver for a USB light (the device consists of three colored LEDs). I have managed to get the driver to load and unload without problems and also create the device (/dev/wn0, /dev/wn1, etc.). However, I keep getting errors when attempting to write to the device:

$ echo "1" >/dev/wn0
bash: echo: write error: Broken pipe

该模块的完整代码是此处.但是,有趣的部分是wn_set_color()函数:

The entire code for the module is here. However, the interesting part is the wn_set_color() function:

/* Create the data buffer to be sent to the device. */
u8 buf[8] = {
    red, green, blue, 0, 0, 0, 0x1F, 0x05
};

/* Send the data to the device. */
return usb_control_msg(udev,
                       usb_sndctrlpipe(udev, 0),
                       0, 0, 0, 0,
                       buf, 8, 0);

由于某种原因,它返回-32而不是将数据发送到设备.

For some reason, it returns -32 instead of sending the data to the device.

我对Linux内核编程完全陌生,所以我可能做一些愚蠢的事情.如果您能对此有所了解,将不胜感激.

I am completely new to Linux kernel programming so I'm likely doing something silly. If you can shed some light on this at all, it would be greatly appreciated.

这是一些其他信息:

usb_endpoint_descriptor类的bDescriptorType成员包含设备公开的单个端点的"5"(bEndpointAddress129-或0x81以十六进制表示)

the bDescriptorType member of the usb_endpoint_descriptor class contains '5' for the single endpoint exposed by the device (bEndpointAddress is 129 - or 0x81 in hex)

此处是发送给用户的控制URB之一的屏幕抓图设备

here is a screengrab of one of the control URBs sent to the device

推荐答案

usb_control_msg()最终调用到usb_submit_urb(). Documentation/usb/error-codes.txt 文件描述了此函数可以返回的错误:

usb_control_msg() eventually calls down to usb_submit_urb(). The Documentation/usb/error-codes.txt file describes the errors that this function can return:

-EPIPE          The pipe type specified in the URB doesn't match the
                endpoint's actual type.

如果usb_submit_urb()成功,则usb_control_msg()返回urb->status值.这在EPIPE下列出:

If usb_submit_urb() succeeded, then usb_control_msg() returns an urb->status value. This lists under EPIPE:

-EPIPE (**)             Endpoint stalled.  For non-control endpoints,
                        reset this status with usb_clear_halt().

(**) This is also one of several codes that different kinds of host
controller use to indicate a transfer has failed because of device
disconnect.  In the interval before the hub driver starts disconnect
processing, devices may receive such fault reports for every request.

您是否检查了内核日志中的任何消息?

Have you checked for any messages in the kernel log?

这篇关于为什么我的内核模块会抛出“断线"?尝试写入设备时出现错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆