Skip to content
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

remove "num_iso_packets" from structure "struct usbi_transfer" #890

Open
lerdmann opened this issue Mar 15, 2021 · 1 comment
Open

remove "num_iso_packets" from structure "struct usbi_transfer" #890

lerdmann opened this issue Mar 15, 2021 · 1 comment
Labels
core Related to common codes isoc isochronous transfer, especially under Windows

Comments

@lerdmann
Copy link

lerdmann commented Mar 15, 2021

"num_iso_packets" is defined in both, "struct usbi_transfer" and also in "struct libusb_transfer".

This can lead to a clash as function "libusb_alloc_transfer" will set the value in "struct usbi_transfer" whereas function "libusb_fill_iso_transfer" will set the value in "struct libusb_transfer" which can lead to a mismatch.

I suggest to change "libusb_alloc_transfer" to :

DEFAULT_VISIBILITY struct libusb_transfer * LIBUSB_CALL libusb_alloc_transfer(int iso_packets)
{
size_t priv_size;
size_t alloc_size;
unsigned char *ptr;
struct usbi_transfer *itransfer;
struct libusb_transfer *transfer;

assert(iso_packets >= 0);
if (iso_packets < 0)
	return NULL;

priv_size = PTR_ALIGN(usbi_backend.transfer_priv_size);
alloc_size = priv_size
	+ sizeof(struct usbi_transfer)
	+ sizeof(struct libusb_transfer)
	+ (sizeof(struct libusb_iso_packet_descriptor) * (size_t)iso_packets);
ptr = calloc(1, alloc_size);
if (!ptr)
	return NULL;

itransfer = (struct usbi_transfer *)(ptr + priv_size);
itransfer->priv = ptr;
usbi_mutex_init(&itransfer->lock);
transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
usbi_dbg("transfer %p", transfer);
    if (transfer) transfer->num_iso_packets = iso_packets;
return transfer;
}

and to remove parameter "num_iso_packets" from structure "struct usbi_transfer" and also remove parameter "num_iso_packets" from function "libusb_fill_iso_transfer" or ignore it (leave as deprecated). That will ensure that there is only one value for "num_iso_packets" and that this value will always be an integral part of the transfer (albeit zero for control,bulk and interrupt transfers) and not some internal control variable.

@mcuee mcuee added the core Related to common codes label Mar 16, 2021
@mcuee mcuee added the isoc isochronous transfer, especially under Windows label Aug 20, 2021
@mcuee
Copy link
Member

mcuee commented Apr 1, 2022

@lerdmann Just wondering if you can create a pull request for this. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Related to common codes isoc isochronous transfer, especially under Windows
Projects
None yet
Development

No branches or pull requests

2 participants