diff mbox series

[net-next,v2,2/2] net/ncsi: Use str_up_down to simplify the code

Message ID 20240827025246.963115-3-lihongbo22@huawei.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series net/ncsi: Use str_up_down to simplify the code | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit fail Errors and warnings before: 15 this patch: 18
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 5 of 5 maintainers
netdev/build_clang fail Errors and warnings before: 16 this patch: 20
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn fail Errors and warnings before: 15 this patch: 18
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 8 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Hongbo Li Aug. 27, 2024, 2:52 a.m. UTC
As str_up_down is the common helper to reback "up/down"
string, we can replace the target with it to simplify
the code and fix the coccinelle warning.

Signed-off-by: Hongbo Li <lihongbo22@huawei.com>
---
 net/ncsi/ncsi-aen.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

kernel test robot Aug. 27, 2024, 6:26 p.m. UTC | #1
Hi Hongbo,

kernel test robot noticed the following build errors:

[auto build test ERROR on net-next/main]

url:    https://github.com/intel-lab-lkp/linux/commits/Hongbo-Li/net-ncsi-Use-str_up_down-to-simplify-the-code/20240827-104622
base:   net-next/main
patch link:    https://lore.kernel.org/r/20240827025246.963115-3-lihongbo22%40huawei.com
patch subject: [PATCH net-next v2 2/2] net/ncsi: Use str_up_down to simplify the code
config: arc-randconfig-001-20240827 (https://download.01.org/0day-ci/archive/20240828/202408280152.l51y5bcU-lkp@intel.com/config)
compiler: arc-elf-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240828/202408280152.l51y5bcU-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202408280152.l51y5bcU-lkp@intel.com/

All error/warnings (new ones prefixed by >>):

   In file included from include/linux/skbuff.h:38,
                    from include/net/net_namespace.h:43,
                    from include/linux/netdevice.h:38,
                    from net/ncsi/ncsi-aen.c:9:
   net/ncsi/ncsi-aen.c: In function 'ncsi_aen_handler_lsc':
>> net/ncsi/ncsi-aen.c:78:28: error: implicit declaration of function 'str_up_down' [-Werror=implicit-function-declaration]
      78 |                    nc->id, str_up_down(data & 0x1));
         |                            ^~~~~~~~~~~
   include/net/net_debug.h:66:60: note: in definition of macro 'netdev_dbg'
      66 |                 netdev_printk(KERN_DEBUG, __dev, format, ##args); \
         |                                                            ^~~~
>> net/ncsi/ncsi-aen.c:77:35: warning: format '%s' expects argument of type 'char *', but argument 5 has type 'int' [-Wformat=]
      77 |         netdev_dbg(ndp->ndev.dev, "NCSI: LSC AEN - channel %u state %s\n",
         |                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      78 |                    nc->id, str_up_down(data & 0x1));
         |                            ~~~~~~~~~~~~~~~~~~~~~~~
         |                            |
         |                            int
   include/net/net_debug.h:66:50: note: in definition of macro 'netdev_dbg'
      66 |                 netdev_printk(KERN_DEBUG, __dev, format, ##args); \
         |                                                  ^~~~~~
   net/ncsi/ncsi-aen.c:77:70: note: format string is defined here
      77 |         netdev_dbg(ndp->ndev.dev, "NCSI: LSC AEN - channel %u state %s\n",
         |                                                                     ~^
         |                                                                      |
         |                                                                      char *
         |                                                                     %d
   cc1: some warnings being treated as errors


vim +/str_up_down +78 net/ncsi/ncsi-aen.c

   > 9	#include <linux/netdevice.h>
    10	#include <linux/skbuff.h>
    11	
    12	#include <net/ncsi.h>
    13	#include <net/net_namespace.h>
    14	#include <net/sock.h>
    15	
    16	#include "internal.h"
    17	#include "ncsi-pkt.h"
    18	
    19	static int ncsi_validate_aen_pkt(struct ncsi_aen_pkt_hdr *h,
    20					 const unsigned short payload)
    21	{
    22		u32 checksum;
    23		__be32 *pchecksum;
    24	
    25		if (h->common.revision != NCSI_PKT_REVISION)
    26			return -EINVAL;
    27		if (ntohs(h->common.length) != payload)
    28			return -EINVAL;
    29	
    30		/* Validate checksum, which might be zeroes if the
    31		 * sender doesn't support checksum according to NCSI
    32		 * specification.
    33		 */
    34		pchecksum = (__be32 *)((void *)(h + 1) + payload - 4);
    35		if (ntohl(*pchecksum) == 0)
    36			return 0;
    37	
    38		checksum = ncsi_calculate_checksum((unsigned char *)h,
    39						   sizeof(*h) + payload - 4);
    40		if (*pchecksum != htonl(checksum))
    41			return -EINVAL;
    42	
    43		return 0;
    44	}
    45	
    46	static int ncsi_aen_handler_lsc(struct ncsi_dev_priv *ndp,
    47					struct ncsi_aen_pkt_hdr *h)
    48	{
    49		struct ncsi_channel *nc, *tmp;
    50		struct ncsi_channel_mode *ncm;
    51		unsigned long old_data, data;
    52		struct ncsi_aen_lsc_pkt *lsc;
    53		struct ncsi_package *np;
    54		bool had_link, has_link;
    55		unsigned long flags;
    56		bool chained;
    57		int state;
    58	
    59		/* Find the NCSI channel */
    60		ncsi_find_package_and_channel(ndp, h->common.channel, NULL, &nc);
    61		if (!nc)
    62			return -ENODEV;
    63	
    64		/* Update the link status */
    65		lsc = (struct ncsi_aen_lsc_pkt *)h;
    66	
    67		spin_lock_irqsave(&nc->lock, flags);
    68		ncm = &nc->modes[NCSI_MODE_LINK];
    69		old_data = ncm->data[2];
    70		data = ntohl(lsc->status);
    71		ncm->data[2] = data;
    72		ncm->data[4] = ntohl(lsc->oem_status);
    73	
    74		had_link = !!(old_data & 0x1);
    75		has_link = !!(data & 0x1);
    76	
  > 77		netdev_dbg(ndp->ndev.dev, "NCSI: LSC AEN - channel %u state %s\n",
  > 78			   nc->id, str_up_down(data & 0x1));
    79	
    80		chained = !list_empty(&nc->link);
    81		state = nc->state;
    82		spin_unlock_irqrestore(&nc->lock, flags);
    83	
    84		if (state == NCSI_CHANNEL_INACTIVE)
    85			netdev_warn(ndp->ndev.dev,
    86				    "NCSI: Inactive channel %u received AEN!\n",
    87				    nc->id);
    88	
    89		if ((had_link == has_link) || chained)
    90			return 0;
    91	
    92		if (!ndp->multi_package && !nc->package->multi_channel) {
    93			if (had_link) {
    94				ndp->flags |= NCSI_DEV_RESHUFFLE;
    95				ncsi_stop_channel_monitor(nc);
    96				spin_lock_irqsave(&ndp->lock, flags);
    97				list_add_tail_rcu(&nc->link, &ndp->channel_queue);
    98				spin_unlock_irqrestore(&ndp->lock, flags);
    99				return ncsi_process_next_channel(ndp);
   100			}
   101			/* Configured channel came up */
   102			return 0;
   103		}
   104	
   105		if (had_link) {
   106			ncm = &nc->modes[NCSI_MODE_TX_ENABLE];
   107			if (ncsi_channel_is_last(ndp, nc)) {
   108				/* No channels left, reconfigure */
   109				return ncsi_reset_dev(&ndp->ndev);
   110			} else if (ncm->enable) {
   111				/* Need to failover Tx channel */
   112				ncsi_update_tx_channel(ndp, nc->package, nc, NULL);
   113			}
   114		} else if (has_link && nc->package->preferred_channel == nc) {
   115			/* Return Tx to preferred channel */
   116			ncsi_update_tx_channel(ndp, nc->package, NULL, nc);
   117		} else if (has_link) {
   118			NCSI_FOR_EACH_PACKAGE(ndp, np) {
   119				NCSI_FOR_EACH_CHANNEL(np, tmp) {
   120					/* Enable Tx on this channel if the current Tx
   121					 * channel is down.
   122					 */
   123					ncm = &tmp->modes[NCSI_MODE_TX_ENABLE];
   124					if (ncm->enable &&
   125					    !ncsi_channel_has_link(tmp)) {
   126						ncsi_update_tx_channel(ndp, nc->package,
   127								       tmp, nc);
   128						break;
   129					}
   130				}
   131			}
   132		}
   133	
   134		/* Leave configured channels active in a multi-channel scenario so
   135		 * AEN events are still received.
   136		 */
   137		return 0;
   138	}
   139
diff mbox series

Patch

diff --git a/net/ncsi/ncsi-aen.c b/net/ncsi/ncsi-aen.c
index 62fb1031763d..25814f06d7da 100644
--- a/net/ncsi/ncsi-aen.c
+++ b/net/ncsi/ncsi-aen.c
@@ -75,7 +75,7 @@  static int ncsi_aen_handler_lsc(struct ncsi_dev_priv *ndp,
 	has_link = !!(data & 0x1);
 
 	netdev_dbg(ndp->ndev.dev, "NCSI: LSC AEN - channel %u state %s\n",
-		   nc->id, data & 0x1 ? "up" : "down");
+		   nc->id, str_up_down(data & 0x1));
 
 	chained = !list_empty(&nc->link);
 	state = nc->state;