Skip to content

Commit

Permalink
Merge tag 'char-misc-5.19-rc6' of git://git.kernel.org/pub/scm/linux/…
Browse files Browse the repository at this point in the history
…kernel/git/gregkh/char-misc

Pull char/misc driver fixes from Greg KH:
 "Here are four small char/misc driver fixes for 5.19-rc6 to resolve
  some reported issues. They only affect two drivers:

   - rtsx_usb: fix for of-reported DMA warning error, the driver was
     handling memory buffers in odd ways, it has now been fixed up to be
     much simpler and correct by Shuah.

   - at25 eeprom driver bugfix for reported problem

  All of these have been in linux-next for a week with no reported
  problems"

* tag 'char-misc-5.19-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc:
  misc: rtsx_usb: set return value in rsp_buf alloc err path
  misc: rtsx_usb: use separate command and response buffers
  misc: rtsx_usb: fix use of dma mapped buffer for usb bulk transfer
  eeprom: at25: Rework buggy read splitting
  • Loading branch information
torvalds committed Jul 10, 2022
2 parents d9919d4 + 2cd37c2 commit b41362f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 24 deletions.
27 changes: 19 additions & 8 deletions drivers/misc/cardreader/rtsx_usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -631,16 +631,20 @@ static int rtsx_usb_probe(struct usb_interface *intf,

ucr->pusb_dev = usb_dev;

ucr->iobuf = usb_alloc_coherent(ucr->pusb_dev, IOBUF_SIZE,
GFP_KERNEL, &ucr->iobuf_dma);
if (!ucr->iobuf)
ucr->cmd_buf = kmalloc(IOBUF_SIZE, GFP_KERNEL);
if (!ucr->cmd_buf)
return -ENOMEM;

ucr->rsp_buf = kmalloc(IOBUF_SIZE, GFP_KERNEL);
if (!ucr->rsp_buf) {
ret = -ENOMEM;
goto out_free_cmd_buf;
}

usb_set_intfdata(intf, ucr);

ucr->vendor_id = id->idVendor;
ucr->product_id = id->idProduct;
ucr->cmd_buf = ucr->rsp_buf = ucr->iobuf;

mutex_init(&ucr->dev_mutex);

Expand Down Expand Up @@ -668,8 +672,11 @@ static int rtsx_usb_probe(struct usb_interface *intf,

out_init_fail:
usb_set_intfdata(ucr->pusb_intf, NULL);
usb_free_coherent(ucr->pusb_dev, IOBUF_SIZE, ucr->iobuf,
ucr->iobuf_dma);
kfree(ucr->rsp_buf);
ucr->rsp_buf = NULL;
out_free_cmd_buf:
kfree(ucr->cmd_buf);
ucr->cmd_buf = NULL;
return ret;
}

Expand All @@ -682,8 +689,12 @@ static void rtsx_usb_disconnect(struct usb_interface *intf)
mfd_remove_devices(&intf->dev);

usb_set_intfdata(ucr->pusb_intf, NULL);
usb_free_coherent(ucr->pusb_dev, IOBUF_SIZE, ucr->iobuf,
ucr->iobuf_dma);

kfree(ucr->cmd_buf);
ucr->cmd_buf = NULL;

kfree(ucr->rsp_buf);
ucr->rsp_buf = NULL;
}

#ifdef CONFIG_PM
Expand Down
26 changes: 12 additions & 14 deletions drivers/misc/eeprom/at25.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,9 @@ static int at25_ee_read(void *priv, unsigned int offset,
struct at25_data *at25 = priv;
char *buf = val;
size_t max_chunk = spi_max_transfer_size(at25->spi);
size_t num_msgs = DIV_ROUND_UP(count, max_chunk);
size_t nr_bytes = 0;
unsigned int msg_offset;
size_t msg_count;
unsigned int msg_offset = offset;
size_t bytes_left = count;
size_t segment;
u8 *cp;
ssize_t status;
struct spi_transfer t[2];
Expand All @@ -97,9 +96,8 @@ static int at25_ee_read(void *priv, unsigned int offset,
if (unlikely(!count))
return -EINVAL;

msg_offset = (unsigned int)offset;
msg_count = min(count, max_chunk);
while (num_msgs) {
do {
segment = min(bytes_left, max_chunk);
cp = at25->command;

instr = AT25_READ;
Expand Down Expand Up @@ -131,8 +129,8 @@ static int at25_ee_read(void *priv, unsigned int offset,
t[0].len = at25->addrlen + 1;
spi_message_add_tail(&t[0], &m);

t[1].rx_buf = buf + nr_bytes;
t[1].len = msg_count;
t[1].rx_buf = buf;
t[1].len = segment;
spi_message_add_tail(&t[1], &m);

status = spi_sync(at25->spi, &m);
Expand All @@ -142,10 +140,10 @@ static int at25_ee_read(void *priv, unsigned int offset,
if (status)
return status;

--num_msgs;
msg_offset += msg_count;
nr_bytes += msg_count;
}
msg_offset += segment;
buf += segment;
bytes_left -= segment;
} while (bytes_left > 0);

dev_dbg(&at25->spi->dev, "read %zu bytes at %d\n",
count, offset);
Expand Down Expand Up @@ -229,7 +227,7 @@ static int at25_ee_write(void *priv, unsigned int off, void *val, size_t count)
do {
unsigned long timeout, retries;
unsigned segment;
unsigned offset = (unsigned) off;
unsigned offset = off;
u8 *cp = bounce;
int sr;
u8 instr;
Expand Down
2 changes: 0 additions & 2 deletions include/linux/rtsx_usb.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ struct rtsx_ucr {
struct usb_device *pusb_dev;
struct usb_interface *pusb_intf;
struct usb_sg_request current_sg;
unsigned char *iobuf;
dma_addr_t iobuf_dma;

struct timer_list sg_timer;
struct mutex dev_mutex;
Expand Down

0 comments on commit b41362f

Please sign in to comment.