Skip to content

Kernel attach and bulk fixes #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fixed USBDevice read locked after interfaces attach/detach
  • Loading branch information
TREFOU Felix authored and Felix TREFOU committed Mar 31, 2025
commit a6f0daef74a3ade65fe75c404b134aa0abef49db
20 changes: 20 additions & 0 deletions src/main/java/org/usb4java/javax/AbstractDevice.java
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,14 @@ public final void close()
}
}

public final void reset()
{
if (this.handle != null)
{
LibUsb.resetDevice(this.handle);
}
}

@Override
public final UsbPort getParentUsbPort()
{
Expand Down Expand Up @@ -400,6 +408,12 @@ final void setActiveUsbConfigurationNumber(final byte number)
final void claimInterface(final byte number, final boolean force)
throws UsbException
{
if(this.claimedInterfaceNumbers.isEmpty()) {
// This prevent a libus bug where async read could lock
// forever after a full released interfaces
reset();
}

if (this.claimedInterfaceNumbers.contains(number))
throw new UsbClaimException("An interface is already claimed");

Expand Down Expand Up @@ -468,6 +482,12 @@ final void releaseInterface(final byte number) throws UsbException
}

this.claimedInterfaceNumbers.remove(number);

if(this.claimedInterfaceNumbers.isEmpty()) {
// This prevent a libus bug where async read could lock
// forever after a full released interfaces
reset();
}
}

/**
Expand Down