]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
net: macb: simplify macb_dma_desc_get_size()
authorThéo Lebrun <theo.lebrun@bootlin.com>
Tue, 14 Oct 2025 15:25:07 +0000 (17:25 +0200)
committerJakub Kicinski <kuba@kernel.org>
Thu, 16 Oct 2025 23:59:25 +0000 (16:59 -0700)
macb_dma_desc_get_size() does a switch on bp->hw_dma_cap and covers all
four cases: 0, 64B, PTP, 64B+PTP. It also covers the #ifndef
MACB_EXT_DESC separately, making it four codepaths.

Instead, notice the descriptor size grows with enabled features and use
plain if-statements on 64B and PTP flags.

Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com>
Link: https://patch.msgid.link/20251014-macb-cleanup-v1-6-31cd266e22cd@bootlin.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/cadence/macb_main.c

index 33e99aab1dcb360a699d0e80762ef421001d19a1..7f74e280a3351ee7f961ff5ecd9550470b2e68eb 100644 (file)
@@ -121,29 +121,16 @@ struct sifive_fu540_macb_mgmt {
  */
 static unsigned int macb_dma_desc_get_size(struct macb *bp)
 {
+       unsigned int desc_size = sizeof(struct macb_dma_desc);
+
 #ifdef MACB_EXT_DESC
-       unsigned int desc_size;
+       if (bp->hw_dma_cap & HW_DMA_CAP_64B)
+               desc_size += sizeof(struct macb_dma_desc_64);
+       if (bp->hw_dma_cap & HW_DMA_CAP_PTP)
+               desc_size += sizeof(struct macb_dma_desc_ptp);
+#endif
 
-       switch (bp->hw_dma_cap) {
-       case HW_DMA_CAP_64B:
-               desc_size = sizeof(struct macb_dma_desc)
-                       + sizeof(struct macb_dma_desc_64);
-               break;
-       case HW_DMA_CAP_PTP:
-               desc_size = sizeof(struct macb_dma_desc)
-                       + sizeof(struct macb_dma_desc_ptp);
-               break;
-       case HW_DMA_CAP_64B_PTP:
-               desc_size = sizeof(struct macb_dma_desc)
-                       + sizeof(struct macb_dma_desc_64)
-                       + sizeof(struct macb_dma_desc_ptp);
-               break;
-       default:
-               desc_size = sizeof(struct macb_dma_desc);
-       }
        return desc_size;
-#endif
-       return sizeof(struct macb_dma_desc);
 }
 
 static unsigned int macb_adj_dma_desc_idx(struct macb *bp, unsigned int desc_idx)