Skip to content

Commit 69d3973

Browse files
arndbmchehab
authored andcommitted
[media] ttpci: address stringop overflow warning
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 <[email protected]> Signed-off-by: Mauro Carvalho Chehab <[email protected]>
1 parent 0051453 commit 69d3973

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

drivers/media/pci/ttpci/av7110_hw.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@
5353
by Nathan Laredo <[email protected]> */
5454

5555
int av7110_debiwrite(struct av7110 *av7110, u32 config,
56-
int addr, u32 val, int count)
56+
int addr, u32 val, unsigned int count)
5757
{
5858
struct saa7146_dev *dev = av7110->dev;
5959

60-
if (count <= 0 || count > 32764) {
60+
if (count > 32764) {
6161
printk("%s: invalid count %d\n", __func__, count);
6262
return -1;
6363
}
@@ -75,12 +75,12 @@ int av7110_debiwrite(struct av7110 *av7110, u32 config,
7575
return 0;
7676
}
7777

78-
u32 av7110_debiread(struct av7110 *av7110, u32 config, int addr, int count)
78+
u32 av7110_debiread(struct av7110 *av7110, u32 config, int addr, unsigned int count)
7979
{
8080
struct saa7146_dev *dev = av7110->dev;
8181
u32 result = 0;
8282

83-
if (count > 32764 || count <= 0) {
83+
if (count > 32764) {
8484
printk("%s: invalid count %d\n", __func__, count);
8585
return 0;
8686
}

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)