pppoe: little cleanup

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

pppoe: little cleanup

Klemens Nanni-2
I'm going through the pppoeintr() code path wrt. KERNEL_LOCK(), first
step is discovery packet handling.

Reading the code makes me want to clean/simplify it a bit by zapping
needless variable assignments (dead store because next usage is another
assign) and merging initializations into declerations.

I'm running with this (and other diffs) just fine.

Feedback? OK?


Index: if_pppoe.c
===================================================================
RCS file: /cvs/src/sys/net/if_pppoe.c,v
retrieving revision 1.73
diff -u -p -r1.73 if_pppoe.c
--- if_pppoe.c 13 Sep 2020 11:00:40 -0000 1.73
+++ if_pppoe.c 13 Sep 2020 15:45:00 -0000
@@ -359,26 +359,22 @@ pppoeintr(void)
 /* Analyze and handle a single received packet while not in session state. */
 static void pppoe_dispatch_disc_pkt(struct mbuf *m, int off)
 {
- struct pppoe_softc *sc;
+ struct pppoe_softc *sc = NULL;
  struct pppoehdr *ph;
  struct pppoetag *pt;
  struct mbuf *n;
  struct ether_header *eh;
- const char *err_msg, *devname;
- size_t ac_cookie_len;
- size_t relay_sid_len;
- int noff, err, errortag;
- u_int16_t *max_payload;
+ const char *err_msg = NULL, *devname = "pppoe";
+ size_t ac_cookie_len = 0;
+ size_t relay_sid_len = 0;
+ int noff, err, errortag = 0;
+ u_int16_t *max_payload = NULL;
  u_int16_t tag, len;
  u_int16_t session, plen;
- u_int8_t *ac_cookie;
- u_int8_t *relay_sid;
+ u_int8_t *ac_cookie = NULL;
+ u_int8_t *relay_sid = 0;
  u_int8_t code;
 
- err_msg = NULL;
- devname = "pppoe";
- errortag = 0;
-
  if (m->m_len < sizeof(*eh)) {
  m = m_pullup(m, sizeof(*eh));
  if (m == NULL)
@@ -387,13 +383,6 @@ static void pppoe_dispatch_disc_pkt(stru
  eh = mtod(m, struct ether_header *);
  off += sizeof(*eh);
 
- ac_cookie = NULL;
- ac_cookie_len = 0;
- relay_sid = NULL;
- relay_sid_len = 0;
- max_payload = NULL;
-
- session = 0;
  if (m->m_pkthdr.len - off <= PPPOE_HEADERLEN) {
  printf("pppoe: packet too short: %d\n", m->m_pkthdr.len);
  goto done;
@@ -425,9 +414,6 @@ static void pppoe_dispatch_disc_pkt(stru
  /* ignore trailing garbage */
  m_adj(m, off + plen - m->m_pkthdr.len);
 
- tag = 0;
- len = 0;
- sc = NULL;
  while (off + sizeof(*pt) <= m->m_pkthdr.len) {
  n = m_pulldown(m, off, sizeof(*pt), &noff);
  if (n == NULL) {