[11/15] hdlcdrv: remove HDLCDRV_MAGIC

Message ID ad19b20f5867e845a843884bbb0f107e7ea7e11a.1666822928.git.nabijaczleweli@nabijaczleweli.xyz
State New
Headers
Series [01/15] hamradio: baycom: remove BAYCOM_MAGIC |

Commit Message

Ahelenia Ziemiańska Oct. 26, 2022, 10:43 p.m. UTC
  We have largely moved away from this approach,
and we have better debugging instrumentation nowadays: kill it

Additionally, ~half HDLCDRV_MAGIC checks just early-exit instead
of noting the bug, so they're detrimental, if anything

Ref: https://lore.kernel.org/linux-doc/YyMlovoskUcHLEb7@kroah.com/
Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
---
 Documentation/process/magic-number.rst                   | 1 -
 .../translations/it_IT/process/magic-number.rst          | 1 -
 .../translations/zh_CN/process/magic-number.rst          | 1 -
 .../translations/zh_TW/process/magic-number.rst          | 1 -
 drivers/net/hamradio/baycom_par.c                        | 1 -
 drivers/net/hamradio/baycom_ser_fdx.c                    | 3 +--
 drivers/net/hamradio/baycom_ser_hdx.c                    | 3 +--
 drivers/net/hamradio/hdlcdrv.c                           | 9 +++------
 include/linux/hdlcdrv.h                                  | 2 --
 9 files changed, 5 insertions(+), 17 deletions(-)
  

Comments

Bagas Sanjaya Oct. 28, 2022, 1:54 p.m. UTC | #1
On 10/27/22 05:43, наб wrote:
> We have largely moved away from this approach,
> and we have better debugging instrumentation nowadays: kill it
> 

Same reply as [1].

> Additionally, ~half HDLCDRV_MAGIC checks just early-exit instead
> of noting the bug, so they're detrimental, if anything
> 

"... instead of handling the magic number"?

Thanks.

[1]: https://lore.kernel.org/linux-doc/80c998ec-435f-158c-9b45-4e6844f7861b@gmail.com/
  

Patch

diff --git a/Documentation/process/magic-number.rst b/Documentation/process/magic-number.rst
index c1c68c713cbc..3b3e607e1cbc 100644
--- a/Documentation/process/magic-number.rst
+++ b/Documentation/process/magic-number.rst
@@ -70,6 +70,5 @@  Magic Name            Number           Structure                File
 ===================== ================ ======================== ==========================================
 FASYNC_MAGIC          0x4601           fasync_struct            ``include/linux/fs.h``
 SLIP_MAGIC            0x5302           slip                     ``drivers/net/slip.h``
-HDLCDRV_MAGIC         0x5ac6e778       hdlcdrv_state            ``include/linux/hdlcdrv.h``
 CCB_MAGIC             0xf2691ad2       ccb                      ``drivers/scsi/ncr53c8xx.c``
 ===================== ================ ======================== ==========================================
diff --git a/Documentation/translations/it_IT/process/magic-number.rst b/Documentation/translations/it_IT/process/magic-number.rst
index 5b609ca78a14..e8c659b6a743 100644
--- a/Documentation/translations/it_IT/process/magic-number.rst
+++ b/Documentation/translations/it_IT/process/magic-number.rst
@@ -76,6 +76,5 @@  Nome magico           Numero           Struttura                File
 ===================== ================ ======================== ==========================================
 FASYNC_MAGIC          0x4601           fasync_struct            ``include/linux/fs.h``
 SLIP_MAGIC            0x5302           slip                     ``drivers/net/slip.h``
-HDLCDRV_MAGIC         0x5ac6e778       hdlcdrv_state            ``include/linux/hdlcdrv.h``
 CCB_MAGIC             0xf2691ad2       ccb                      ``drivers/scsi/ncr53c8xx.c``
 ===================== ================ ======================== ==========================================
diff --git a/Documentation/translations/zh_CN/process/magic-number.rst b/Documentation/translations/zh_CN/process/magic-number.rst
index ab4d4e32b61f..2105af32187c 100644
--- a/Documentation/translations/zh_CN/process/magic-number.rst
+++ b/Documentation/translations/zh_CN/process/magic-number.rst
@@ -59,6 +59,5 @@  Linux 魔术数
 ===================== ================ ======================== ==========================================
 FASYNC_MAGIC          0x4601           fasync_struct            ``include/linux/fs.h``
 SLIP_MAGIC            0x5302           slip                     ``drivers/net/slip.h``
-HDLCDRV_MAGIC         0x5ac6e778       hdlcdrv_state            ``include/linux/hdlcdrv.h``
 CCB_MAGIC             0xf2691ad2       ccb                      ``drivers/scsi/ncr53c8xx.c``
 ===================== ================ ======================== ==========================================
diff --git a/Documentation/translations/zh_TW/process/magic-number.rst b/Documentation/translations/zh_TW/process/magic-number.rst
index a6131d978189..793a0ae9fb7c 100644
--- a/Documentation/translations/zh_TW/process/magic-number.rst
+++ b/Documentation/translations/zh_TW/process/magic-number.rst
@@ -62,6 +62,5 @@  Linux 魔術數
 ===================== ================ ======================== ==========================================
 FASYNC_MAGIC          0x4601           fasync_struct            ``include/linux/fs.h``
 SLIP_MAGIC            0x5302           slip                     ``drivers/net/slip.h``
-HDLCDRV_MAGIC         0x5ac6e778       hdlcdrv_state            ``include/linux/hdlcdrv.h``
 CCB_MAGIC             0xf2691ad2       ccb                      ``drivers/scsi/ncr53c8xx.c``
 ===================== ================ ======================== ==========================================
diff --git a/drivers/net/hamradio/baycom_par.c b/drivers/net/hamradio/baycom_par.c
index fd7da5bb1fa5..e1cf3ed42df6 100644
--- a/drivers/net/hamradio/baycom_par.c
+++ b/drivers/net/hamradio/baycom_par.c
@@ -418,7 +418,6 @@  static int baycom_ioctl(struct net_device *dev, void __user *data,
 		return -EINVAL;
 
 	bc = netdev_priv(dev);
-	BUG_ON(bc->hdrv.magic != HDLCDRV_MAGIC);
 
 	if (cmd != SIOCDEVPRIVATE)
 		return -ENOIOCTLCMD;
diff --git a/drivers/net/hamradio/baycom_ser_fdx.c b/drivers/net/hamradio/baycom_ser_fdx.c
index 646f605e358f..65113cb6de8d 100644
--- a/drivers/net/hamradio/baycom_ser_fdx.c
+++ b/drivers/net/hamradio/baycom_ser_fdx.c
@@ -252,7 +252,7 @@  static irqreturn_t ser12_interrupt(int irq, void *dev_id)
 	unsigned char iir, msr;
 	unsigned int txcount = 0;
 
-	if (!bc || bc->hdrv.magic != HDLCDRV_MAGIC)
+	if (!bc)
 		return IRQ_NONE;
 	/* fast way out for shared irq */
 	if ((iir = inb(IIR(dev->base_addr))) & 1) 	
@@ -507,7 +507,6 @@  static int baycom_ioctl(struct net_device *dev, void __user *data,
 		return -EINVAL;
 
 	bc = netdev_priv(dev);
-	BUG_ON(bc->hdrv.magic != HDLCDRV_MAGIC);
 
 	if (cmd != SIOCDEVPRIVATE)
 		return -ENOIOCTLCMD;
diff --git a/drivers/net/hamradio/baycom_ser_hdx.c b/drivers/net/hamradio/baycom_ser_hdx.c
index 5d1ab4840753..df33e5cdb5c2 100644
--- a/drivers/net/hamradio/baycom_ser_hdx.c
+++ b/drivers/net/hamradio/baycom_ser_hdx.c
@@ -365,7 +365,7 @@  static irqreturn_t ser12_interrupt(int irq, void *dev_id)
 	struct baycom_state *bc = netdev_priv(dev);
 	unsigned char iir;
 
-	if (!dev || !bc || bc->hdrv.magic != HDLCDRV_MAGIC)
+	if (!dev || !bc)
 		return IRQ_NONE;
 	/* fast way out */
 	if ((iir = inb(IIR(dev->base_addr))) & 1)
@@ -561,7 +561,6 @@  static int baycom_ioctl(struct net_device *dev, void __user *data,
 		return -EINVAL;
 
 	bc = netdev_priv(dev);
-	BUG_ON(bc->hdrv.magic != HDLCDRV_MAGIC);
 
 	if (cmd != SIOCDEVPRIVATE)
 		return -ENOIOCTLCMD;
diff --git a/drivers/net/hamradio/hdlcdrv.c b/drivers/net/hamradio/hdlcdrv.c
index 2263029d1a20..60abd6008cc7 100644
--- a/drivers/net/hamradio/hdlcdrv.c
+++ b/drivers/net/hamradio/hdlcdrv.c
@@ -158,7 +158,7 @@  void hdlcdrv_receiver(struct net_device *dev, struct hdlcdrv_state *s)
 	int i;
 	unsigned int mask1, mask2, mask3, mask4, mask5, mask6, word;
 	
-	if (!s || s->magic != HDLCDRV_MAGIC) 
+	if (!s)
 		return;
 	if (test_and_set_bit(0, &s->hdlcrx.in_hdlc_rx))
 		return;
@@ -257,7 +257,7 @@  void hdlcdrv_transmitter(struct net_device *dev, struct hdlcdrv_state *s)
 	struct sk_buff *skb;
 	int pkt_len;
 
-	if (!s || s->magic != HDLCDRV_MAGIC) 
+	if (!s)
 		return;
 	if (test_and_set_bit(0, &s->hdlctx.in_hdlc_tx))
 		return;
@@ -364,7 +364,7 @@  static void start_tx(struct net_device *dev, struct hdlcdrv_state *s)
 
 void hdlcdrv_arbitrate(struct net_device *dev, struct hdlcdrv_state *s)
 {
-	if (!s || s->magic != HDLCDRV_MAGIC || s->hdlctx.ptt || !s->skb) 
+	if (!s || s->hdlctx.ptt || !s->skb)
 		return;
 	if (s->ch_params.fulldup) {
 		start_tx(dev, s);
@@ -701,7 +701,6 @@  struct net_device *hdlcdrv_register(const struct hdlcdrv_ops *ops,
 	 * initialize part of the hdlcdrv_state struct
 	 */
 	s = netdev_priv(dev);
-	s->magic = HDLCDRV_MAGIC;
 	s->ops = ops;
 	dev->base_addr = baseaddr;
 	dev->irq = irq;
@@ -723,8 +722,6 @@  void hdlcdrv_unregister(struct net_device *dev)
 {
 	struct hdlcdrv_state *s = netdev_priv(dev);
 
-	BUG_ON(s->magic != HDLCDRV_MAGIC);
-
 	if (s->opened && s->ops->close)
 		s->ops->close(dev);
 	unregister_netdev(dev);
diff --git a/include/linux/hdlcdrv.h b/include/linux/hdlcdrv.h
index 5d70c3f98f5b..809ad0f5c99c 100644
--- a/include/linux/hdlcdrv.h
+++ b/include/linux/hdlcdrv.h
@@ -13,7 +13,6 @@ 
 #include <linux/spinlock.h>
 #include <uapi/linux/hdlcdrv.h>
 
-#define HDLCDRV_MAGIC      0x5ac6e778
 #define HDLCDRV_HDLCBUFFER  32 /* should be a power of 2 for speed reasons */
 #define HDLCDRV_BITBUFFER  256 /* should be a power of 2 for speed reasons */
 #undef HDLCDRV_LOOPBACK  /* define for HDLC debugging purposes */
@@ -84,7 +83,6 @@  struct hdlcdrv_ops {
 };
 
 struct hdlcdrv_state {
-	int magic;
 	int opened;
 
 	const struct hdlcdrv_ops *ops;