Skip to content

Commit b41362f

Browse files
committed
Merge tag 'char-misc-5.19-rc6' of git://git.kernel.org/pub/scm/linux/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
2 parents d9919d4 + 2cd37c2 commit b41362f

File tree

3 files changed

+31
-24
lines changed

3 files changed

+31
-24
lines changed

drivers/misc/cardreader/rtsx_usb.c

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -631,16 +631,20 @@ static int rtsx_usb_probe(struct usb_interface *intf,
631631

632632
ucr->pusb_dev = usb_dev;
633633

634-
ucr->iobuf = usb_alloc_coherent(ucr->pusb_dev, IOBUF_SIZE,
635-
GFP_KERNEL, &ucr->iobuf_dma);
636-
if (!ucr->iobuf)
634+
ucr->cmd_buf = kmalloc(IOBUF_SIZE, GFP_KERNEL);
635+
if (!ucr->cmd_buf)
637636
return -ENOMEM;
638637

638+
ucr->rsp_buf = kmalloc(IOBUF_SIZE, GFP_KERNEL);
639+
if (!ucr->rsp_buf) {
640+
ret = -ENOMEM;
641+
goto out_free_cmd_buf;
642+
}
643+
639644
usb_set_intfdata(intf, ucr);
640645

641646
ucr->vendor_id = id->idVendor;
642647
ucr->product_id = id->idProduct;
643-
ucr->cmd_buf = ucr->rsp_buf = ucr->iobuf;
644648

645649
mutex_init(&ucr->dev_mutex);
646650

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

669673
out_init_fail:
670674
usb_set_intfdata(ucr->pusb_intf, NULL);
671-
usb_free_coherent(ucr->pusb_dev, IOBUF_SIZE, ucr->iobuf,
672-
ucr->iobuf_dma);
675+
kfree(ucr->rsp_buf);
676+
ucr->rsp_buf = NULL;
677+
out_free_cmd_buf:
678+
kfree(ucr->cmd_buf);
679+
ucr->cmd_buf = NULL;
673680
return ret;
674681
}
675682

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

684691
usb_set_intfdata(ucr->pusb_intf, NULL);
685-
usb_free_coherent(ucr->pusb_dev, IOBUF_SIZE, ucr->iobuf,
686-
ucr->iobuf_dma);
692+
693+
kfree(ucr->cmd_buf);
694+
ucr->cmd_buf = NULL;
695+
696+
kfree(ucr->rsp_buf);
697+
ucr->rsp_buf = NULL;
687698
}
688699

689700
#ifdef CONFIG_PM

drivers/misc/eeprom/at25.c

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,9 @@ static int at25_ee_read(void *priv, unsigned int offset,
8080
struct at25_data *at25 = priv;
8181
char *buf = val;
8282
size_t max_chunk = spi_max_transfer_size(at25->spi);
83-
size_t num_msgs = DIV_ROUND_UP(count, max_chunk);
84-
size_t nr_bytes = 0;
85-
unsigned int msg_offset;
86-
size_t msg_count;
83+
unsigned int msg_offset = offset;
84+
size_t bytes_left = count;
85+
size_t segment;
8786
u8 *cp;
8887
ssize_t status;
8988
struct spi_transfer t[2];
@@ -97,9 +96,8 @@ static int at25_ee_read(void *priv, unsigned int offset,
9796
if (unlikely(!count))
9897
return -EINVAL;
9998

100-
msg_offset = (unsigned int)offset;
101-
msg_count = min(count, max_chunk);
102-
while (num_msgs) {
99+
do {
100+
segment = min(bytes_left, max_chunk);
103101
cp = at25->command;
104102

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

134-
t[1].rx_buf = buf + nr_bytes;
135-
t[1].len = msg_count;
132+
t[1].rx_buf = buf;
133+
t[1].len = segment;
136134
spi_message_add_tail(&t[1], &m);
137135

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

145-
--num_msgs;
146-
msg_offset += msg_count;
147-
nr_bytes += msg_count;
148-
}
143+
msg_offset += segment;
144+
buf += segment;
145+
bytes_left -= segment;
146+
} while (bytes_left > 0);
149147

150148
dev_dbg(&at25->spi->dev, "read %zu bytes at %d\n",
151149
count, offset);
@@ -229,7 +227,7 @@ static int at25_ee_write(void *priv, unsigned int off, void *val, size_t count)
229227
do {
230228
unsigned long timeout, retries;
231229
unsigned segment;
232-
unsigned offset = (unsigned) off;
230+
unsigned offset = off;
233231
u8 *cp = bounce;
234232
int sr;
235233
u8 instr;

include/linux/rtsx_usb.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ struct rtsx_ucr {
5454
struct usb_device *pusb_dev;
5555
struct usb_interface *pusb_intf;
5656
struct usb_sg_request current_sg;
57-
unsigned char *iobuf;
58-
dma_addr_t iobuf_dma;
5957

6058
struct timer_list sg_timer;
6159
struct mutex dev_mutex;

0 commit comments

Comments
 (0)