Skip to content

Commit dbc97bf

Browse files
tom-seewaldgregkh
authored andcommitted
net: liquidio: Add missing null pointer checks
The functions send_rx_ctrl_cmd() in both liquidio/lio_main.c and liquidio/lio_vf_main.c do not check if the call to octeon_alloc_soft_command() fails and returns a null pointer. Both functions also return void so errors are not propagated back to the caller. Fix these issues by updating both instances of send_rx_ctrl_cmd() to return an integer rather than void, and have them return -ENOMEM if an allocation failure occurs. Also update all callers of send_rx_ctrl_cmd() so that they now check the return value. Cc: David S. Miller <[email protected]> Signed-off-by: Tom Seewald <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 4fd798a commit dbc97bf

File tree

2 files changed

+40
-15
lines changed

2 files changed

+40
-15
lines changed

drivers/net/ethernet/cavium/liquidio/lio_main.c

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,19 +1153,24 @@ static void octeon_destroy_resources(struct octeon_device *oct)
11531153
* @lio: per-network private data
11541154
* @start_stop: whether to start or stop
11551155
*/
1156-
static void send_rx_ctrl_cmd(struct lio *lio, int start_stop)
1156+
static int send_rx_ctrl_cmd(struct lio *lio, int start_stop)
11571157
{
11581158
struct octeon_soft_command *sc;
11591159
union octnet_cmd *ncmd;
11601160
struct octeon_device *oct = (struct octeon_device *)lio->oct_dev;
11611161
int retval;
11621162

11631163
if (oct->props[lio->ifidx].rx_on == start_stop)
1164-
return;
1164+
return 0;
11651165

11661166
sc = (struct octeon_soft_command *)
11671167
octeon_alloc_soft_command(oct, OCTNET_CMD_SIZE,
11681168
16, 0);
1169+
if (!sc) {
1170+
netif_info(lio, rx_err, lio->netdev,
1171+
"Failed to allocate octeon_soft_command struct\n");
1172+
return -ENOMEM;
1173+
}
11691174

11701175
ncmd = (union octnet_cmd *)sc->virtdptr;
11711176

@@ -1187,18 +1192,19 @@ static void send_rx_ctrl_cmd(struct lio *lio, int start_stop)
11871192
if (retval == IQ_SEND_FAILED) {
11881193
netif_info(lio, rx_err, lio->netdev, "Failed to send RX Control message\n");
11891194
octeon_free_soft_command(oct, sc);
1190-
return;
11911195
} else {
11921196
/* Sleep on a wait queue till the cond flag indicates that the
11931197
* response arrived or timed-out.
11941198
*/
11951199
retval = wait_for_sc_completion_timeout(oct, sc, 0);
11961200
if (retval)
1197-
return;
1201+
return retval;
11981202

11991203
oct->props[lio->ifidx].rx_on = start_stop;
12001204
WRITE_ONCE(sc->caller_is_done, true);
12011205
}
1206+
1207+
return retval;
12021208
}
12031209

12041210
/**
@@ -1773,6 +1779,7 @@ static int liquidio_open(struct net_device *netdev)
17731779
struct octeon_device_priv *oct_priv =
17741780
(struct octeon_device_priv *)oct->priv;
17751781
struct napi_struct *napi, *n;
1782+
int ret = 0;
17761783

17771784
if (oct->props[lio->ifidx].napi_enabled == 0) {
17781785
tasklet_disable(&oct_priv->droq_tasklet);
@@ -1808,7 +1815,9 @@ static int liquidio_open(struct net_device *netdev)
18081815
netif_info(lio, ifup, lio->netdev, "Interface Open, ready for traffic\n");
18091816

18101817
/* tell Octeon to start forwarding packets to host */
1811-
send_rx_ctrl_cmd(lio, 1);
1818+
ret = send_rx_ctrl_cmd(lio, 1);
1819+
if (ret)
1820+
return ret;
18121821

18131822
/* start periodical statistics fetch */
18141823
INIT_DELAYED_WORK(&lio->stats_wk.work, lio_fetch_stats);
@@ -1819,7 +1828,7 @@ static int liquidio_open(struct net_device *netdev)
18191828
dev_info(&oct->pci_dev->dev, "%s interface is opened\n",
18201829
netdev->name);
18211830

1822-
return 0;
1831+
return ret;
18231832
}
18241833

18251834
/**
@@ -1833,6 +1842,7 @@ static int liquidio_stop(struct net_device *netdev)
18331842
struct octeon_device_priv *oct_priv =
18341843
(struct octeon_device_priv *)oct->priv;
18351844
struct napi_struct *napi, *n;
1845+
int ret = 0;
18361846

18371847
ifstate_reset(lio, LIO_IFSTATE_RUNNING);
18381848

@@ -1849,7 +1859,9 @@ static int liquidio_stop(struct net_device *netdev)
18491859
lio->link_changes++;
18501860

18511861
/* Tell Octeon that nic interface is down. */
1852-
send_rx_ctrl_cmd(lio, 0);
1862+
ret = send_rx_ctrl_cmd(lio, 0);
1863+
if (ret)
1864+
return ret;
18531865

18541866
if (OCTEON_CN23XX_PF(oct)) {
18551867
if (!oct->msix_on)
@@ -1884,7 +1896,7 @@ static int liquidio_stop(struct net_device *netdev)
18841896

18851897
dev_info(&oct->pci_dev->dev, "%s interface is stopped\n", netdev->name);
18861898

1887-
return 0;
1899+
return ret;
18881900
}
18891901

18901902
/**

drivers/net/ethernet/cavium/liquidio/lio_vf_main.c

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -595,19 +595,24 @@ static void octeon_destroy_resources(struct octeon_device *oct)
595595
* @lio: per-network private data
596596
* @start_stop: whether to start or stop
597597
*/
598-
static void send_rx_ctrl_cmd(struct lio *lio, int start_stop)
598+
static int send_rx_ctrl_cmd(struct lio *lio, int start_stop)
599599
{
600600
struct octeon_device *oct = (struct octeon_device *)lio->oct_dev;
601601
struct octeon_soft_command *sc;
602602
union octnet_cmd *ncmd;
603603
int retval;
604604

605605
if (oct->props[lio->ifidx].rx_on == start_stop)
606-
return;
606+
return 0;
607607

608608
sc = (struct octeon_soft_command *)
609609
octeon_alloc_soft_command(oct, OCTNET_CMD_SIZE,
610610
16, 0);
611+
if (!sc) {
612+
netif_info(lio, rx_err, lio->netdev,
613+
"Failed to allocate octeon_soft_command struct\n");
614+
return -ENOMEM;
615+
}
611616

612617
ncmd = (union octnet_cmd *)sc->virtdptr;
613618

@@ -635,11 +640,13 @@ static void send_rx_ctrl_cmd(struct lio *lio, int start_stop)
635640
*/
636641
retval = wait_for_sc_completion_timeout(oct, sc, 0);
637642
if (retval)
638-
return;
643+
return retval;
639644

640645
oct->props[lio->ifidx].rx_on = start_stop;
641646
WRITE_ONCE(sc->caller_is_done, true);
642647
}
648+
649+
return retval;
643650
}
644651

645652
/**
@@ -906,6 +913,7 @@ static int liquidio_open(struct net_device *netdev)
906913
struct octeon_device_priv *oct_priv =
907914
(struct octeon_device_priv *)oct->priv;
908915
struct napi_struct *napi, *n;
916+
int ret = 0;
909917

910918
if (!oct->props[lio->ifidx].napi_enabled) {
911919
tasklet_disable(&oct_priv->droq_tasklet);
@@ -932,11 +940,13 @@ static int liquidio_open(struct net_device *netdev)
932940
(LIQUIDIO_NDEV_STATS_POLL_TIME_MS));
933941

934942
/* tell Octeon to start forwarding packets to host */
935-
send_rx_ctrl_cmd(lio, 1);
943+
ret = send_rx_ctrl_cmd(lio, 1);
944+
if (ret)
945+
return ret;
936946

937947
dev_info(&oct->pci_dev->dev, "%s interface is opened\n", netdev->name);
938948

939-
return 0;
949+
return ret;
940950
}
941951

942952
/**
@@ -950,9 +960,12 @@ static int liquidio_stop(struct net_device *netdev)
950960
struct octeon_device_priv *oct_priv =
951961
(struct octeon_device_priv *)oct->priv;
952962
struct napi_struct *napi, *n;
963+
int ret = 0;
953964

954965
/* tell Octeon to stop forwarding packets to host */
955-
send_rx_ctrl_cmd(lio, 0);
966+
ret = send_rx_ctrl_cmd(lio, 0);
967+
if (ret)
968+
return ret;
956969

957970
netif_info(lio, ifdown, lio->netdev, "Stopping interface!\n");
958971
/* Inform that netif carrier is down */
@@ -986,7 +999,7 @@ static int liquidio_stop(struct net_device *netdev)
986999

9871000
dev_info(&oct->pci_dev->dev, "%s interface is stopped\n", netdev->name);
9881001

989-
return 0;
1002+
return ret;
9901003
}
9911004

9921005
/**

0 commit comments

Comments
 (0)