Skip to content

Commit 15b4f99

Browse files
Alex Elderdavem330
authored andcommitted
net: ipa: avoid a null pointer dereference
Dan Carpenter reported that Smatch found an instance where a pointer which had previously been assumed could be null (as indicated by a null check) was later dereferenced without a similar check. In practice this doesn't lead to a problem because currently the pointers used are all non-null. Nevertheless this patch addresses the reported problem. In addition, I spotted another bug that arose in the same commit. When the command to initialize a routing table memory region was added, the number of entries computed for the non-hashed table was wrong (it ended up being a Boolean rather than the count intended). This bug is fixed here as well. Reported-by: Dan Carpenter <[email protected]> Link: https://lore.kernel.org/kernel-janitors/Y3OOP9dXK6oEydkf@kili Tested-by: Caleb Connolly <[email protected]> Fixes: 5cb7689 ("net: ipa: reduce arguments to ipa_table_init_add()") Signed-off-by: Alex Elder <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent c609d73 commit 15b4f99

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

drivers/net/ipa/ipa_table.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,7 @@ static void ipa_table_init_add(struct gsi_trans *trans, bool filter, bool ipv6)
382382
const struct ipa_mem *mem;
383383
dma_addr_t hash_addr;
384384
dma_addr_t addr;
385+
u32 hash_offset;
385386
u32 zero_offset;
386387
u16 hash_count;
387388
u32 zero_size;
@@ -394,8 +395,10 @@ static void ipa_table_init_add(struct gsi_trans *trans, bool filter, bool ipv6)
394395
: ipv6 ? IPA_CMD_IP_V6_ROUTING_INIT
395396
: IPA_CMD_IP_V4_ROUTING_INIT;
396397

398+
/* The non-hashed region will exist (see ipa_table_mem_valid()) */
397399
mem = ipa_table_mem(ipa, filter, false, ipv6);
398400
hash_mem = ipa_table_mem(ipa, filter, true, ipv6);
401+
hash_offset = hash_mem ? hash_mem->offset : 0;
399402

400403
/* Compute the number of table entries to initialize */
401404
if (filter) {
@@ -411,7 +414,7 @@ static void ipa_table_init_add(struct gsi_trans *trans, bool filter, bool ipv6)
411414
* of entries it has.
412415
*/
413416
count = mem->size / sizeof(__le64);
414-
hash_count = hash_mem && hash_mem->size / sizeof(__le64);
417+
hash_count = hash_mem ? hash_mem->size / sizeof(__le64) : 0;
415418
}
416419
size = count * sizeof(__le64);
417420
hash_size = hash_count * sizeof(__le64);
@@ -420,7 +423,7 @@ static void ipa_table_init_add(struct gsi_trans *trans, bool filter, bool ipv6)
420423
hash_addr = ipa_table_addr(ipa, filter, hash_count);
421424

422425
ipa_cmd_table_init_add(trans, opcode, size, mem->offset, addr,
423-
hash_size, hash_mem->offset, hash_addr);
426+
hash_size, hash_offset, hash_addr);
424427
if (!filter)
425428
return;
426429

@@ -433,7 +436,7 @@ static void ipa_table_init_add(struct gsi_trans *trans, bool filter, bool ipv6)
433436
return;
434437

435438
/* Zero the unused space in the hashed filter table */
436-
zero_offset = hash_mem->offset + hash_size;
439+
zero_offset = hash_offset + hash_size;
437440
zero_size = hash_mem->size - hash_size;
438441
ipa_cmd_dma_shared_mem_add(trans, zero_offset, zero_size,
439442
ipa->zero_addr, true);

0 commit comments

Comments
 (0)