From e67c4ea8e6b30f1f10f3408fd432b07e5b7df96e Mon Sep 17 00:00:00 2001 From: sys64738 Date: Sun, 25 Jul 2021 19:47:22 +0200 Subject: [PATCH] fix /dev/dmj-* chardevs not appearing when not in mode 1 --- host/dmctl.sh | 1 + host/modules/dmj-char.c | 1 + host/modules/dmj.c | 26 +++++++++++++++++--------- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/host/dmctl.sh b/host/dmctl.sh index 5c80daa..ac65d16 100755 --- a/host/dmctl.sh +++ b/host/dmctl.sh @@ -1,2 +1,3 @@ #!/bin/sh +cd "$(dirname "$(realpath "$0")")" exec python3 -m dmctl "$@" diff --git a/host/modules/dmj-char.c b/host/modules/dmj-char.c index 0160b84..b43d0ca 100644 --- a/host/modules/dmj-char.c +++ b/host/modules/dmj-char.c @@ -59,6 +59,7 @@ static ssize_t dmj_char_read(struct file *file, char *buf, size_t len, loff_t *l /* no flags: act like libusb read */ res = dmj_transfer(dmjch->pdev, -1, 0/*DMJ_XFER_FLAGS_FILL_RECVBUF*/, NULL, 0, &kbuf, &ilen); if (res < 0 || ilen < 0 || !kbuf) { + //dev_warn(dev, "err res=%d ilen=%d kbuf=%p\n", res, ilen, kbuf); if (kbuf) kfree(kbuf); return (res >= 0) ? -EIO : ret; } diff --git a/host/modules/dmj.c b/host/modules/dmj.c index ed7debc..be694b4 100644 --- a/host/modules/dmj.c +++ b/host/modules/dmj.c @@ -227,7 +227,10 @@ int dmj_xfer_internal(struct dmj_dev *dmj, int cmd, int recvflags, * will error when going beyond!). also done in 64b chunks */ - if (!rbufsize || *rbufsize <= 0) return 0; + if (!rbufsize || *rbufsize <= 0) { + //dev_warn(dev, "no rbuf\n"); + return 0; + } if (recvflags & DMJ_XFER_FLAGS_FILL_RECVBUF) { tmpbuf = kmalloc(64, GFP_KERNEL); @@ -265,7 +268,10 @@ int dmj_xfer_internal(struct dmj_dev *dmj, int cmd, int recvflags, ret = usb_bulk_msg(dmj->usb_dev, usb_rcvbulkpipe(dmj->usb_dev, dmj->ep_in), longbuf, *rbufsize, rbufsize, DMJ_USB_TIMEOUT); if (ret < 0) goto err_freelong; - if (*rbufsize < 0) ret = -EREMOTEIO; goto err_freelong; + if (*rbufsize < 0) { + //dev_warn(dev, "remoteio\n"); + ret = -EREMOTEIO; goto err_freelong; + } ret = 0; *rbuf = longbuf; @@ -450,8 +456,10 @@ static int dmj_probe(struct usb_interface *itf, const struct usb_device_id *usb_ struct dmj_dev *dmj; int ret, i; - if (hostitf->desc.bNumEndpoints < 2) + if (hostitf->desc.bNumEndpoints < 2) { + dev_warn(dev, "not enough endpoints!\n"); return -ENODEV; + } for (i = 0; i < hostitf->desc.bNumEndpoints; ++i) { curep = &hostitf->endpoint[i].desc; @@ -488,13 +496,13 @@ static int dmj_probe(struct usb_interface *itf, const struct usb_device_id *usb_ goto out_free; } - if (dmj->dmj_mode == 1) { - ret = mfd_add_hotplug_devices(dev, dmj_mfd_char, ARRAY_SIZE(dmj_mfd_char)); - if (ret) { - dev_err(dev, "failed to add MFD character devices\n"); - goto out_free; - } + ret = mfd_add_hotplug_devices(dev, dmj_mfd_char, ARRAY_SIZE(dmj_mfd_char)); + if (ret) { + dev_err(dev, "failed to add MFD character devices\n"); + goto out_free; + } + if (dmj->dmj_mode == 1) { if (dmj->dmj_m1feature & DMJ_FEATURE_MODE1_SPI) { ret = mfd_add_hotplug_devices(dev, dmj_mfd_spi, ARRAY_SIZE(dmj_mfd_spi)); if (ret) {