Skip to contentSkip to conversation

fpga: dfl: fme: add performance reporting support

bug report Dan Carpenter 3 participants 3 messages May 2, 2020 – May 7, 2020 FPGA manager framework

lore
Share & tools
lore
#0 lore raw

Hello Wu Hao,

The patch 724142f8c42a: "fpga: dfl: fme: add performance reporting support" from Apr 27, 2020, leads to the following static checker warning:

	drivers/fpga/dfl-fme-perf.c:948 fme_perf_offline_cpu()
	error: potential NULL dereference 'priv'.

drivers/fpga/dfl-fme-perf.c
941 static int fme_perf_offline_cpu(unsigned int cpu, struct hlist_node *node) 942 {
943 struct fme_perf_priv *priv;
944 int target;
945

   946          priv = hlist_entry_safe(node, struct fme_perf_priv, node);
                                  ^^^^^

It doesn't make sense to use the _safe() version if we're not going to check for NULL.

   947  
   948          if (cpu != priv->cpu)
   949                  return 0;
   950  
   951          target = cpumask_any_but(cpu_online_mask, cpu);
   952          if (target >= nr_cpu_ids)
   953                  return 0;
   954  
   955          priv->cpu = target;
   956          return 0;
   957  }

regards,
dan carpenter

maintainer
#1 lore raw
Quoted 11 lines · Dan Carpenter

Hello Wu Hao,

The patch 724142f8c42a: "fpga: dfl: fme: add performance reporting support" from Apr 27, 2020, leads to the following static checker warning:

	drivers/fpga/dfl-fme-perf.c:948 fme_perf_offline_cpu()
	error: potential NULL dereference 'priv'.

drivers/fpga/dfl-fme-perf.c
941 static int fme_perf_offline_cpu(unsigned int cpu, struct hlist_node *node)

Quoted 8 lines
   942  {
   943          struct fme_perf_priv *priv;
   944          int target;
   945  
   946          priv = hlist_entry_safe(node, struct fme_perf_priv, node);
                                  ^^^^^

It doesn't make sense to use the _safe() version if we're not going to check for NULL.

Thanks for catching this. Will fix it.

Regards,
Yilun.

Quoted 15 lines
   947  
   948          if (cpu != priv->cpu)
   949                  return 0;
   950  
   951          target = cpumask_any_but(cpu_online_mask, cpu);
   952          if (target >= nr_cpu_ids)
   953                  return 0;
   954  
   955          priv->cpu = target;
   956          return 0;
   957  }

regards,
dan carpenter

#2 lore raw
Quoted 22 lines · Dan Carpenter
Quoted 11 lines

Hello Wu Hao,

The patch 724142f8c42a: "fpga: dfl: fme: add performance reporting support" from Apr 27, 2020, leads to the following static checker warning:

	drivers/fpga/dfl-fme-perf.c:948 fme_perf_offline_cpu()
	error: potential NULL dereference 'priv'.

drivers/fpga/dfl-fme-perf.c
941 static int fme_perf_offline_cpu(unsigned int cpu, struct hlist_node

*node)

Quoted 8 lines
   942  {
   943          struct fme_perf_priv *priv;
   944          int target;
   945
   946          priv = hlist_entry_safe(node, struct fme_perf_priv, node);
                                  ^^^^^

It doesn't make sense to use the _safe() version if we're not going to check for NULL.

Quoted 1 line

Thanks for catching this. Will fix it.

Yes, it's not necessary to use _safe version here.
Thanks Dan for reporting this, and thanks Yilun for covering this when I was on leave.

Hao

Quoted 19 lines

Regards,
Yilun.

Quoted 15 lines
   947
   948          if (cpu != priv->cpu)
   949                  return 0;
   950
   951          target = cpumask_any_but(cpu_online_mask, cpu);
   952          if (target >= nr_cpu_ids)
   953                  return 0;
   954
   955          priv->cpu = target;
   956          return 0;
   957  }

regards,
dan carpenter