Skip to contentSkip to conversation

media: dvb_ca_en50221: bail out of write loop on non-positive fraglen

PATCH New Muhammad Bilal 1 participant 1 message Sep 19 Media (V4L/DVB)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 media: dvb_ca_en50221: bail out of write loop on non-positive fraglen

dvb_ca_en50221_io_write() derives fraglen from sl->link_buf_size, a value negotiated with the CAM in dvb_ca_en50221_link_init() and only ever clamped on the high end against HOST_LINK_BUF_SIZE. The loop guards against a negative fraglen (link_buf_size < 2) but not against fraglen == 0 (link_buf_size == 2 exactly): "fragpos += fraglen" at the bottom of the loop then adds zero, so fragpos never reaches count and the write() never returns while a positive count remains to be sent.

Treat a non-positive fraglen the same as a negative one and stop fragmenting, consistent with how the existing check already handles link_buf_size < 2.

---
 drivers/media/dvb-core/dvb_ca_en50221.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/dvb-core/dvb_ca_en50221.c +1 -1
index 1b91ebb8f667..9131f62c1258 100644
@@ -1487,7 +1487,7 @@ static ssize_t dvb_ca_en50221_io_write(struct file *file,
 	/* fragment the packets & store in the buffer */
 	while (fragpos < count) {
 		fraglen = sl->link_buf_size - 2;
-		if (fraglen < 0)
+		if (fraglen <= 0)
 			break;
 		if (fraglen > HOST_LINK_BUF_SIZE - 2)
 			fraglen = HOST_LINK_BUF_SIZE - 2;
Signature · 1 line
2.55.0