Commit 0cb58cfb87dfc05bfc4e8c29fc0767621e251d09

Authored by Ye Li
1 parent e215385fcb

net: fec_mxc: Fix DM driver issue in recv

When using ethernet DM driver, the recv interface has a
change with non-DM interface, that driver needs to set
the packet pointer and provide it to upper layer to process.

In fec driver, the fecmxc_recv functions does not handle the
packet pointer parameter. This may cause crash in upper layer
processing because the packet pointer is not set.

This patch allocates a buffer for the packet pointer and free it
through free_pkt interface.

Signed-off-by: Ye Li <ye.li@nxp.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

Showing 1 changed file with 23 additions and 0 deletions Side-by-side Diff

drivers/net/fec_mxc.c
... ... @@ -806,7 +806,16 @@
806 806 uint16_t bd_status;
807 807 ulong addr, size, end;
808 808 int i;
  809 +
  810 +#ifdef CONFIG_DM_ETH
  811 + *packetp = memalign(ARCH_DMA_MINALIGN, FEC_MAX_PKT_SIZE);
  812 + if (*packetp == 0) {
  813 + printf("%s: error allocating packetp\n", __func__);
  814 + return -ENOMEM;
  815 + }
  816 +#else
809 817 ALLOC_CACHE_ALIGN_BUFFER(uchar, buff, FEC_MAX_PKT_SIZE);
  818 +#endif
810 819  
811 820 /* Check if any critical events have happened */
812 821 ievent = readl(&fec->eth->ievent);
813 822  
... ... @@ -882,8 +891,13 @@
882 891 #ifdef CONFIG_FEC_MXC_SWAP_PACKET
883 892 swap_packet((uint32_t *)addr, frame_length);
884 893 #endif
  894 +
  895 +#ifdef CONFIG_DM_ETH
  896 + memcpy(*packetp, (char *)addr, frame_length);
  897 +#else
885 898 memcpy(buff, (char *)addr, frame_length);
886 899 net_process_received_packet(buff, frame_length);
  900 +#endif
887 901 len = frame_length;
888 902 } else {
889 903 if (bd_status & FEC_RBD_ERR)
890 904  
... ... @@ -1201,10 +1215,19 @@
1201 1215 return fec_get_hwaddr(priv->dev_id, pdata->enetaddr);
1202 1216 }
1203 1217  
  1218 +static int fecmxc_free_pkt(struct udevice *dev, uchar *packet, int length)
  1219 +{
  1220 + if (packet)
  1221 + free(packet);
  1222 +
  1223 + return 0;
  1224 +}
  1225 +
1204 1226 static const struct eth_ops fecmxc_ops = {
1205 1227 .start = fecmxc_init,
1206 1228 .send = fecmxc_send,
1207 1229 .recv = fecmxc_recv,
  1230 + .free_pkt = fecmxc_free_pkt,
1208 1231 .stop = fecmxc_halt,
1209 1232 .write_hwaddr = fecmxc_set_hwaddr,
1210 1233 .read_rom_hwaddr = fecmxc_read_rom_hwaddr,