Geoff Levand <ge...@infradead.org> a écrit :

Add a new preprocessor macro BUG_ON_DEBUG, that expands to BUG_ON when
the preprocessor macro DEBUG is defined, or to WARN_ON when DEBUG is not
defined.  Also, replace all occurrences of BUG_ON with BUG_ON_DEBUG.

Why is BUG_ON() needed at all if WARN_ON() is enough ?

You just have to set panic_on_warn to get the system to stop at first warning.

BUG_ON() should be avoided unless vital.

Please read https://www.kernel.org/doc/html/latest/process/deprecated.html#bug-and-bug-on

Christophe



Signed-off-by: Geoff Levand <ge...@infradead.org>
---
 drivers/net/ethernet/toshiba/ps3_gelic_net.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/toshiba/ps3_gelic_net.c b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
index ded467d81f36..946e9bfa071b 100644
--- a/drivers/net/ethernet/toshiba/ps3_gelic_net.c
+++ b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
@@ -44,6 +44,13 @@ MODULE_AUTHOR("SCE Inc.");
 MODULE_DESCRIPTION("Gelic Network driver");
 MODULE_LICENSE("GPL");

+#define BUG_ON_DEBUG(_cond) do { \
+       if (__is_defined(DEBUG)) \
+               BUG_ON(_cond); \
+       else \
+               WARN_ON(_cond); \
+} while (0)
+
 int gelic_card_set_irq_mask(struct gelic_card *card, u64 mask)
 {
        struct device *dev = ctodev(card);
@@ -505,7 +512,7 @@ static void gelic_descr_release_tx(struct gelic_card *card,
        struct sk_buff *skb = descr->skb;
        struct device *dev = ctodev(card);

-       BUG_ON(!(be32_to_cpu(descr->hw_regs.data_status) &
+       BUG_ON_DEBUG(!(be32_to_cpu(descr->hw_regs.data_status) &
                GELIC_DESCR_TX_TAIL));

        dma_unmap_single(dev, be32_to_cpu(descr->hw_regs.payload.dev_addr),
@@ -1667,7 +1674,7 @@ static void gelic_card_get_vlan_info(struct gelic_card *card)
        }

        if (card->vlan[GELIC_PORT_ETHERNET_0].tx) {
-               BUG_ON(!card->vlan[GELIC_PORT_WIRELESS].tx);
+               BUG_ON_DEBUG(!card->vlan[GELIC_PORT_WIRELESS].tx);
                card->vlan_required = 1;
        } else
                card->vlan_required = 0;
@@ -1709,7 +1716,7 @@ static int ps3_gelic_driver_probe(struct ps3_system_bus_device *sb_dev)
        if (result) {
                dev_err(dev, "%s:%d: ps3_dma_region_create failed: %d\n",
                        __func__, __LINE__, result);
-               BUG_ON("check region type");
+               BUG_ON_DEBUG("check region type");
                goto fail_dma_region;
        }

--
2.25.1


Reply via email to