mbox series

[00/82] remove unnecessary null checks

Message ID 20220124000518.319850-1-stephen@networkplumber.org (mailing list archive)
Headers show
Series remove unnecessary null checks | expand

Message

Stephen Hemminger Jan. 24, 2022, 12:03 a.m. UTC
While working on a new driver, noticed that some drivers always call
free routines (correct) and others conditionally call free routines
if not null (redundant check).  The extra if(e != NULL) type check
is unneeded and adds extra code.  Better to have all the code
consistent.

The Linux kernel has automated this kind of fixup using coccinelle,
and this patchset creates a coccinelle script to do the transformation;
then has individual patches for each sub component.

In one driver dpaaxx, the change suggested a further change
to the compat macros to make them even simpler.

Stephen Hemminger (82):
  devtools/cocci: add script to fix unnecessary null checks
  eal: remove unnecessary NULL checks
  eal/windows: remove unnecessary NULL checks before free
  examples/fips_validation: remove unnecessary NULL checks
  examples/ip_pipeline: remove unnecessary NULL checks
  examples/pipeline/thread: remove unnecessary NULL checks
  examples/l2fwd-cat: remove unnecessary NULL checks
  lib/vhost: remove unnecessary NULL checks
  examples/vhost_blk: remove unnecessary NULL checks
  app/pdump: remove unnecessary NULL checks
  app/test-crypto-perf: remove unnecessary NULL checks
  app/test-pmd: remove unnecessary NULL checks
  app/test-regex: remove unnecessary NULL checks
  app/test: remove unnecessary NULL checks
  baseband/acc100 remove unnecessary NULL checks
  baseband/la12xx remove unnecessary NULL checks
  baseband/null remove unnecessary NULL checks
  baseband/turbo_sw remove unnecessary NULL checks
  bus/fslmc: remove unnecessary NULL checks
  bus/ifpga: remove unnecessary NULL checks
  bus/pci: remove unnecessary NULL checks
  common/cpt: remove unnecessary NULL checks
  common/dpaax: simplify kernel compat macros
  common/mlx5: remove unnecessary NULL checks
  common/qat: remove unnecessary NULL checks
  compress/mlx5: remove unnecessary NULL checks
  compress/octeontx: remove unnecessary NULL checks
  crypto/armv8: remove unnecessary NULL checks
  crypto/ccp: remove unnecessary NULL checks
  crypto/cnxk: remove unnecessary NULL checks
  crypto/ipsec_mb: remove unnecessary NULL checks
  crypto/mvsam: remove unnecessary NULL checks
  crypto/null: remove unnecessary NULL checks
  crypto/octeontx: remove unnecessary NULL checks
  crypto/openssl: remove unnecessary NULL checks
  crypto/scheduler: remove unnecessary NULL checks
  crypto/virtio: remove unnecessary NULL checks
  event/sw: remove unnecessary NULL checks
  net/axgbe: remove unnecessary NULL checks
  net/bnx2x: remove unnecessary NULL checks
  net/bnxt: remove unnecessary NULL checks
  net/bonding: remove unnecessary NULL checks
  net/cnxk: remove unnecessary NULL checks
  net/cxgbe: remove unnecessary NULL checks
  net/dpaa: remove unnecessary NULL checks
  net/dpaa2: remove unnecessary NULL checks
  net/ena: remove unnecessary NULL checks
  net/hinic: remove unnecessary NULL checks
  net/hns3: remove unnecessary NULL checks
  net/i40e: remove unnecessary NULL checks
  net/iavf: remove unnecessary NULL checks
  net/ice: remove unnecessary NULL checks
  net/igc: remove unnecessary NULL checks
  net/ixgbe: remove unnecessary NULL checks
  net/memif: remove unnecessary NULL checks
  net/mlx4: remove unnecessary NULL checks
  net/mlx5: remove unnecessary NULL checks
  net/mvpp2: remove unnecessary NULL checks
  net/netvsc: remove unnecessary NULL checks
  net/null: remove unnecessary NULL checks
  net/octeontx: remove unnecessary NULL checks
  net/qede: remove unnecessary NULL checks
  net/softnic: remove unnecessary NULL checks
  net/tap: remove unnecessary NULL checks
  net/txgbe: remove unnecessary NULL checks
  net/vdev_netvsc: remove unnecessary NULL checks
  net/virtio: remove unnecessary NULL checks
  raw/cnxk_bphy: remove unnecessary NULL checks
  raw/dpaa2_qdma: remove unnecessary NULL checks
  raw/ifpga: remove unnecessary NULL checks
  raw/skeleton: remove unnecessary NULL checks
  regex/cn9k: remove unnecessary NULL checks
  regex/mlx5: remove unnecessary NULL checks
  vdpa/ifc: remove unnecessary NULL checks
  vdpa/mlx5: remove unnecessary NULL checks
  compressdev: remove unnecessary NULL checks
  ethdev: remove unnecessary NULL checks
  graph: remove unnecessary NULL checks
  ipsec: remove unnecessary NULL checks
  port: remove unnecessary NULL checks
  power: remove unnecessary NULL checks
  reorder: remove unnecessary NULL checks

 app/pdump/main.c                              |  9 ++--
 app/test-crypto-perf/cperf_test_latency.c     |  3 +-
 .../cperf_test_pmd_cyclecount.c               |  9 ++--
 app/test-crypto-perf/cperf_test_throughput.c  |  3 +-
 .../cperf_test_vector_parsing.c               |  6 +--
 app/test-crypto-perf/cperf_test_verify.c      |  3 +-
 app/test-pmd/cmd_flex_item.c                  |  3 +-
 app/test-pmd/cmdline.c                        |  3 +-
 app/test-pmd/testpmd.c                        |  3 +-
 app/test-regex/main.c                         | 12 ++---
 app/test/test_cksum.c                         |  3 +-
 app/test/test_compressdev.c                   |  3 +-
 app/test/test_cryptodev.h                     |  3 +-
 app/test/test_cryptodev_asym.c                |  3 +-
 app/test/test_cryptodev_blockcipher.c         | 12 ++---
 app/test/test_func_reentrancy.c               | 15 +++----
 app/test/test_hash.c                          | 15 +++----
 app/test/test_hash_perf.c                     |  7 +--
 app/test/test_link_bonding.c                  |  9 ++--
 app/test/test_link_bonding_mode4.c            |  3 +-
 app/test/test_malloc.c                        |  5 +--
 app/test/test_mbuf.c                          | 45 +++++++------------
 app/test/test_pcapng.c                        |  3 +-
 app/test/test_reorder.c                       | 15 +++----
 app/test/virtual_pmd.c                        |  3 +-
 devtools/cocci/nullfree.cocci                 | 33 ++++++++++++++
 drivers/baseband/acc100/rte_acc100_pmd.c      |  3 +-
 drivers/baseband/la12xx/bbdev_la12xx.c        |  3 +-
 drivers/baseband/null/bbdev_null.c            |  3 +-
 .../baseband/turbo_sw/bbdev_turbo_software.c  |  3 +-
 drivers/bus/fslmc/fslmc_bus.c                 |  6 +--
 drivers/bus/fslmc/portal/dpaa2_hw_dpio.c      |  6 +--
 drivers/bus/ifpga/ifpga_bus.c                 | 12 ++---
 drivers/bus/pci/pci_params.c                  |  3 +-
 drivers/bus/pci/windows/pci.c                 |  3 +-
 drivers/bus/pci/windows/pci_netuio.c          |  3 +-
 drivers/common/cpt/cpt_ucode_asym.h           |  6 +--
 drivers/common/dpaax/compat.h                 | 11 +----
 drivers/common/mlx5/mlx5_common_mr.c          |  3 +-
 drivers/common/mlx5/mlx5_common_pci.c         |  3 +-
 drivers/common/qat/qat_qp.c                   |  9 ++--
 drivers/compress/mlx5/mlx5_compress.c         |  3 +-
 drivers/compress/octeontx/otx_zip_pmd.c       |  9 ++--
 drivers/crypto/armv8/rte_armv8_pmd_ops.c      |  3 +-
 drivers/crypto/ccp/ccp_dev.c                  |  3 +-
 drivers/crypto/ccp/ccp_pmd_ops.c              |  3 +-
 drivers/crypto/cnxk/cnxk_ae.h                 |  6 +--
 drivers/crypto/ipsec_mb/ipsec_mb_ops.c        |  6 +--
 drivers/crypto/mvsam/rte_mrvl_pmd_ops.c       |  6 +--
 drivers/crypto/null/null_crypto_pmd_ops.c     |  6 +--
 drivers/crypto/octeontx/otx_cryptodev_ops.c   |  3 +-
 drivers/crypto/openssl/rte_openssl_pmd_ops.c  |  6 +--
 drivers/crypto/scheduler/scheduler_pmd_ops.c  |  6 +--
 drivers/crypto/virtio/virtqueue.c             |  6 +--
 drivers/event/sw/sw_evdev.c                   |  3 +-
 drivers/net/axgbe/axgbe_rxtx.c                |  6 +--
 drivers/net/bnx2x/bnx2x_rxtx.c                |  6 +--
 drivers/net/bnxt/bnxt_ethdev.c                |  3 +-
 drivers/net/bonding/rte_eth_bond_pmd.c        |  3 +-
 drivers/net/cnxk/cnxk_ethdev.c                |  6 +--
 drivers/net/cxgbe/cxgbe_main.c                |  3 +-
 drivers/net/dpaa/dpaa_ethdev.c                |  3 +-
 drivers/net/dpaa/fmlib/fm_lib.c               |  3 +-
 drivers/net/dpaa2/dpaa2_ethdev.c              |  3 +-
 drivers/net/dpaa2/dpaa2_mux.c                 |  3 +-
 drivers/net/dpaa2/dpaa2_ptp.c                 |  3 +-
 drivers/net/ena/ena_ethdev.c                  | 18 +++-----
 drivers/net/hinic/hinic_pmd_ethdev.c          |  3 +-
 drivers/net/hns3/hns3_rxtx.c                  |  9 ++--
 drivers/net/i40e/i40e_ethdev.c                | 27 ++++-------
 drivers/net/i40e/i40e_rxtx.c                  |  3 +-
 drivers/net/iavf/iavf_rxtx.c                  |  3 +-
 drivers/net/ice/ice_fdir_filter.c             |  6 +--
 drivers/net/igc/igc_flow.c                    |  3 +-
 drivers/net/ixgbe/ixgbe_ethdev.c              | 10 ++---
 drivers/net/ixgbe/ixgbe_rxtx.c                |  3 +-
 drivers/net/memif/rte_eth_memif.c             |  6 +--
 drivers/net/mlx4/mlx4_mr.c                    |  3 +-
 drivers/net/mlx5/mlx5_flow.c                  |  3 +-
 drivers/net/mvpp2/mrvl_qos.c                  |  3 +-
 drivers/net/netvsc/hn_rxtx.c                  |  6 +--
 drivers/net/null/rte_eth_null.c               |  3 +-
 drivers/net/octeontx/octeontx_ethdev.c        |  3 +-
 drivers/net/octeontx/octeontx_ethdev_ops.c    |  3 +-
 drivers/net/qede/qede_main.c                  |  3 +-
 drivers/net/qede/qede_rxtx.c                  |  6 +--
 drivers/net/softnic/rte_eth_softnic_cli.c     | 12 ++---
 .../net/softnic/rte_eth_softnic_cryptodev.c   |  6 +--
 drivers/net/softnic/rte_eth_softnic_thread.c  |  6 +--
 drivers/net/tap/tap_flow.c                    |  9 ++--
 drivers/net/txgbe/txgbe_ethdev.c              | 12 ++---
 drivers/net/vdev_netvsc/vdev_netvsc.c         |  3 +-
 drivers/net/virtio/virtio_user_ethdev.c       | 12 ++---
 drivers/raw/cnxk_bphy/cnxk_bphy_cgx.c         |  3 +-
 drivers/raw/dpaa2_qdma/dpaa2_qdma.c           | 15 +++----
 drivers/raw/ifpga/ifpga_rawdev.c              |  9 ++--
 drivers/raw/skeleton/skeleton_rawdev_test.c   |  6 +--
 drivers/regex/cn9k/cn9k_regexdev.c            |  6 +--
 drivers/regex/cn9k/cn9k_regexdev_compiler.c   |  3 +-
 drivers/regex/mlx5/mlx5_regex.c               |  3 +-
 drivers/regex/mlx5/mlx5_rxp.c                 |  3 +-
 drivers/vdpa/ifc/ifcvf_vdpa.c                 |  9 ++--
 drivers/vdpa/mlx5/mlx5_vdpa_mem.c             |  3 +-
 drivers/vdpa/mlx5/mlx5_vdpa_virtq.c           |  3 +-
 examples/fips_validation/fips_dev_self_test.c | 18 +++-----
 examples/fips_validation/fips_validation.c    |  3 +-
 examples/fips_validation/main.c               | 36 +++++----------
 examples/ip_pipeline/cli.c                    | 12 ++---
 examples/ip_pipeline/cryptodev.c              |  6 +--
 examples/ip_pipeline/thread.c                 |  6 +--
 examples/l2fwd-cat/cat.c                      |  3 +-
 examples/pipeline/thread.c                    |  6 +--
 examples/vhost_blk/vhost_blk.c                |  3 +-
 lib/compressdev/rte_compressdev.c             |  3 +-
 lib/eal/common/eal_common_devargs.c           |  6 +--
 lib/eal/common/eal_common_memzone.c           |  3 +-
 lib/eal/common/eal_common_options.c           |  9 ++--
 lib/eal/common/eal_common_trace_ctf.c         |  6 +--
 lib/eal/freebsd/eal.c                         |  4 +-
 lib/eal/linux/eal.c                           | 10 ++---
 lib/eal/windows/eal_alarm.c                   |  3 +-
 lib/eal/windows/eal_memory.c                  |  3 +-
 lib/ethdev/rte_ethdev.c                       |  3 +-
 lib/graph/graph_stats.c                       |  3 +-
 lib/ipsec/ipsec_sad.c                         |  3 +-
 lib/port/rte_port_source_sink.c               | 21 +++------
 lib/power/rte_power_empty_poll.c              |  3 +-
 lib/reorder/rte_reorder.c                     |  6 +--
 lib/vhost/iotlb.c                             |  3 +-
 lib/vhost/vhost_crypto.c                      |  6 +--
 lib/vhost/vhost_user.c                        |  9 ++--
 131 files changed, 306 insertions(+), 557 deletions(-)
 create mode 100644 devtools/cocci/nullfree.cocci