New filters on the Home Feed, take a look!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

8
C Linux USB Driver | usb_control_msg “Invalid argument” error
Post Flair (click to view more posts with a particular flair)
Post Body

Hello! I'm currently writing an Xbox One controller driver for Linux, however I have come across an issue that I seem to not be able to resolve. In my open syscall below, I'm calling the usb_control_msg() function, in order to get a status update from my device. However, when I access the open syscall in my user-space program, perror returns an error of "Invalid argument". When i check dmesg, I see lots of warnings / errors, yet the usb_control_msg() function still returns a positive number, thus indicating that bytes were successfully transferred to my buffer. Could you please help me out?

Also, when I attempt to print my data buffer, it prints as NULL, even though two bytes were transferred to my data buffer. I'm attempting to print the data buffer with "printk(KERN_INFO "Data: %*phC", data);"

Code:

static int xb1_open(struct inode *inode, struct file *file) {
    printk(KERN_INFO "open function called..");

    struct xb1_controller *dev;
    struct usb_interface *interface;
    int subminor;
    int retval = 0;

    subminor = iminor(inode);

    interface = usb_find_interface(&xb1_driver, subminor);
    if(!interface) {
        printk(KERN_INFO "Unable to locate interface in open  
                  function");
        retval = -ENODEV;
        goto exit;
    }

    dev = usb_get_intfdata(interface);
    if(!dev) {
        printk(KERN_INFO "Unable to locate dev structure in open 
                  function");
        retval = -ENODEV;
        goto exit;
    }

    char data[8];
    memset(&data, 0, sizeof(data));

    retval = usb_control_msg(dev->udev, usb_rcvctrlpipe(dev->udev,   
                  0), USB_REQ_GET_STATUS, USB_DIR_IN, 0, 0, 
                  &data, sizeof(data), 0);
    if(retval < 0) {
        printk(KERN_INFO "usb_control_msg failed | Retval = %d", 
                  retval);
    }
    else {
         printk(KERN_INFO "Retval: %d", retval);
    }

In the below dmesg output, you can see that Retval is assigned a value of 2 (second line):

[ 77.102749] open function called.. [ 77.122795]

Retval: 2

[ 77.123087] ------------[ cut here ]------------ [ 77.123107] WARNING: CPU: 0 PID: 2278 at /build/linux-kOWph6/linux-4.4.0/fs/namei.c:3215 path_openat 0xb19/0x1330()

[ 77.123108] Modules linked in: xpad ff_memless main(OE) snd_intel8x0 snd_ac97_codec ac97_bus crct10dif_pclmul crc32_pclmul snd_pcm snd_seq_midi snd_seq_midi_event vboxvideo aesni_intel aes_x86_64 ttm lrw snd_rawmidi gf128mul drm_kms_helper glue_helper ablk_helper cryptd snd_seq drm snd_seq_device snd_timer joydev input_leds snd fb_sys_fops syscopyarea sysfillrect serio_raw sysimgblt soundcore vboxguest i2c_piix4 mac_hid 8250_fintek parport_pc ppdev lp parport autofs4 hid_generic usbhid hid psmouse ahci libahci e1000 pata_acpi video fjes

[ 77.123152] CPU: 0 PID: 2278 Comm: hello Tainted: G OE 4.4.0-45-generic #66-Ubuntu

[ 77.123154] Hardware name: innotek GmbH VirtualBox/VirtualBox, BIOS VirtualBox 12/01/2006

[ 77.123156] 0000000000000286 000000005d6bd96b ffff8800d980bcb8 ffffffff813f1fe3

[ 77.123159] 0000000000000000 ffffffff81cd8e58 ffff8800d980bcf0 ffffffff81081212

[ 77.123162] ffff8800d980bdd0 0000000000008002 ffff8800d980bef4 00000000ffffffea

[ 77.123165] Call Trace:

[ 77.123172] [] dump_stack 0x63/0x90

[ 77.123177] [] warn_slowpath_common 0x82/0xc0

[ 77.123180] [] warn_slowpath_null 0x1a/0x20

[ 77.123183] [] path_openat 0xb19/0x1330

[ 77.123187] [] do_filp_open 0x91/0x100

[ 77.123191] [] ? rawcallee_save__pv_queued_spin_unlock 0x11/0x20

[ 77.123194] [] ? __alloc_fd 0xc8/0x190

[ 77.123198] [] do_sys_open 0x138/0x2a0

[ 77.123201] [] ? __do_page_fault 0x1b4/0x400

[ 77.123204] [] SyS_open 0x1e/0x20

[ 77.123213] [] entry_SYSCALL_64_fastpath 0x16/0x71

[ 77.123216] ---[ end trace a1ba30f9590f2a36 ]---

Author
Account Strength
80%
Account Age
11 years
Verified Email
Yes
Verified Flair
No
Total Karma
398
Link Karma
165
Comment Karma
233
Profile updated: 3 days ago
Posts updated: 1 year ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
7 years ago