Skip to content

Commit 2536c20

Browse files
arndbgregkh
authored andcommitted
ttpci: address stringop overflow warning
commit 69d3973af1acd4c0989ec8218c05f12d303cd7cf upstream. gcc-7.0.1 warns about old code in ttpci: In file included from drivers/media/pci/ttpci/av7110.c:63:0: In function 'irdebi.isra.2', inlined from 'start_debi_dma' at drivers/media/pci/ttpci/av7110.c:376:3, inlined from 'gpioirq' at drivers/media/pci/ttpci/av7110.c:659:3: drivers/media/pci/ttpci/av7110_hw.h:406:3: warning: 'memcpy': specified size between 18446744071562067968 and 18446744073709551615 exceeds maximum object size 9223372036854775807 [-Wstringop-overflow=] memcpy(av7110->debi_virt, (char *) &res, count); In function 'irdebi.isra.2', inlined from 'start_debi_dma' at drivers/media/pci/ttpci/av7110.c:376:3, inlined from 'gpioirq' at drivers/media/pci/ttpci/av7110.c:668:3: drivers/media/pci/ttpci/av7110_hw.h:406:3: warning: 'memcpy': specified size between 18446744071562067968 and 18446744073709551615 exceeds maximum object size 9223372036854775807 [-Wstringop-overflow=] memcpy(av7110->debi_virt, (char *) &res, count); Apparently, 'count' can be negative here, which will then get turned into a giant size argument for memcpy. Changing the sizes to 'unsigned int' instead seems safe as we already check for maximum sizes, and it also simplifies the code a bit. Signed-off-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 2b2bfb5 commit 2536c20

2 files changed

Lines changed: 10 additions & 10 deletions

File tree

drivers/media/pci/ttpci/av7110_hw.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@
5656
by Nathan Laredo <laredo@gnu.org> */
5757

5858
int av7110_debiwrite(struct av7110 *av7110, u32 config,
59-
int addr, u32 val, int count)
59+
int addr, u32 val, unsigned int count)
6060
{
6161
struct saa7146_dev *dev = av7110->dev;
6262

63-
if (count <= 0 || count > 32764) {
63+
if (count > 32764) {
6464
printk("%s: invalid count %d\n", __func__, count);
6565
return -1;
6666
}
@@ -78,12 +78,12 @@ int av7110_debiwrite(struct av7110 *av7110, u32 config,
7878
return 0;
7979
}
8080

81-
u32 av7110_debiread(struct av7110 *av7110, u32 config, int addr, int count)
81+
u32 av7110_debiread(struct av7110 *av7110, u32 config, int addr, unsigned int count)
8282
{
8383
struct saa7146_dev *dev = av7110->dev;
8484
u32 result = 0;
8585

86-
if (count > 32764 || count <= 0) {
86+
if (count > 32764) {
8787
printk("%s: invalid count %d\n", __func__, count);
8888
return 0;
8989
}

drivers/media/pci/ttpci/av7110_hw.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -377,14 +377,14 @@ extern int av7110_fw_request(struct av7110 *av7110, u16 *request_buf,
377377

378378
/* DEBI (saa7146 data extension bus interface) access */
379379
extern int av7110_debiwrite(struct av7110 *av7110, u32 config,
380-
int addr, u32 val, int count);
380+
int addr, u32 val, unsigned int count);
381381
extern u32 av7110_debiread(struct av7110 *av7110, u32 config,
382-
int addr, int count);
382+
int addr, unsigned int count);
383383

384384

385385
/* DEBI during interrupt */
386386
/* single word writes */
387-
static inline void iwdebi(struct av7110 *av7110, u32 config, int addr, u32 val, int count)
387+
static inline void iwdebi(struct av7110 *av7110, u32 config, int addr, u32 val, unsigned int count)
388388
{
389389
av7110_debiwrite(av7110, config, addr, val, count);
390390
}
@@ -397,7 +397,7 @@ static inline void mwdebi(struct av7110 *av7110, u32 config, int addr,
397397
av7110_debiwrite(av7110, config, addr, 0, count);
398398
}
399399

400-
static inline u32 irdebi(struct av7110 *av7110, u32 config, int addr, u32 val, int count)
400+
static inline u32 irdebi(struct av7110 *av7110, u32 config, int addr, u32 val, unsigned int count)
401401
{
402402
u32 res;
403403

@@ -408,7 +408,7 @@ static inline u32 irdebi(struct av7110 *av7110, u32 config, int addr, u32 val, i
408408
}
409409

410410
/* DEBI outside interrupts, only for count <= 4! */
411-
static inline void wdebi(struct av7110 *av7110, u32 config, int addr, u32 val, int count)
411+
static inline void wdebi(struct av7110 *av7110, u32 config, int addr, u32 val, unsigned int count)
412412
{
413413
unsigned long flags;
414414

@@ -417,7 +417,7 @@ static inline void wdebi(struct av7110 *av7110, u32 config, int addr, u32 val, i
417417
spin_unlock_irqrestore(&av7110->debilock, flags);
418418
}
419419

420-
static inline u32 rdebi(struct av7110 *av7110, u32 config, int addr, u32 val, int count)
420+
static inline u32 rdebi(struct av7110 *av7110, u32 config, int addr, u32 val, unsigned int count)
421421
{
422422
unsigned long flags;
423423
u32 res;

0 commit comments

Comments
 (0)