Skip to contentSkip to conversation

cpufreq: brcmstb-avs-cpufreq: Fix initial command check

bug report Dan Carpenter 1 participant 1 message Aug 20, 2019

lore
Share & tools
lore
#0 lore raw

Hello Florian Fainelli,

The patch 22a26cc6a51e: "cpufreq: brcmstb-avs-cpufreq: Fix initial command check" from May 22, 2019, leads to the following static checker warning:

	drivers/cpufreq/brcmstb-avs-cpufreq.c:449 brcm_avs_is_firmware_loaded()
	warn: was && intended here instead of ||?

drivers/cpufreq/brcmstb-avs-cpufreq.c
435 /*

   436   * To ensure the right firmware is running we need to
   437   *    - check the MAGIC matches what we expect
   438   *    - brcm_avs_get_pmap() doesn't return -ENOTSUPP or -EINVAL
   439   * We need to set up our interrupt handling before calling brcm_avs_get_pmap()!
   440   */

441 static bool brcm_avs_is_firmware_loaded(struct private_data *priv) 442 {
443 u32 magic;
444 int rc;
445
446 rc = brcm_avs_get_pmap(priv, NULL);
447 magic = readl(priv->base + AVS_MBOX_MAGIC);
448
449 return (magic == AVS_FIRMWARE_MAGIC) && ((rc != -ENOTSUPP) ||
450 (rc != -EINVAL));

This is quite an interesting one because originally this was && instead of || as the static checker suggests. Obviously "(rc != -ENOTSUPP || rc != -EINVAL) is always true because "rc" can't possibly be both values at the same time.

I see the comment at the top of the function, but I don't understand why those particular error codes are special. The temptation for me would be to do:

	rc = brcm_avs_get_pmap(priv, NULL);
	if (rc)
		return false;

	magic = readl(priv->base + AVS_MBOX_MAGIC);
	return magic == AVS_FIRMWARE_MAGIC;

But I'm clearly missing some information so I'm just going to report this bug instead.

451 }

regards,
dan carpenter