All of lore.kernel.org
 help / color / mirror / Atom feed
From: kernel test robot <lkp@intel.com>
To: kbuild@lists.01.org
Subject: [tobetter-linux:odroid-5.9.y 66/69] drivers/thermal/thermal_helpers.c:123 thermal_zone_get_temp() error: testing array offset 'tz->id' after use.
Date: Fri, 04 Sep 2020 00:32:58 +0800	[thread overview]
Message-ID: <202009040050.QkhqDHSK%lkp@intel.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 6155 bytes --]

CC: kbuild-all(a)lists.01.org
TO: "charles.park" <charles.park@hardkernel.com>
CC: Dongjin Kim <tobetter@gmail.com>

tree:   https://github.com/tobetter/linux odroid-5.9.y
head:   2f810ed6f99dfcdb64b0df67d13f1632038ddf70
commit: 26ef3eed39da0a6d6d5d35c9e1d1da9d032a78bf [66/69] ODROID-XU4: Update hack avoiding the invalid temperature by TMU broken
:::::: branch date: 8 hours ago
:::::: commit date: 8 hours ago
config: i386-randconfig-m021-20200902 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-15) 9.3.0

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>

smatch warnings:
drivers/thermal/thermal_helpers.c:123 thermal_zone_get_temp() error: testing array offset 'tz->id' after use.

# https://github.com/tobetter/linux/commit/26ef3eed39da0a6d6d5d35c9e1d1da9d032a78bf
git remote add tobetter-linux https://github.com/tobetter/linux
git fetch --no-tags tobetter-linux odroid-5.9.y
git checkout 26ef3eed39da0a6d6d5d35c9e1d1da9d032a78bf
vim +123 drivers/thermal/thermal_helpers.c

26ef3eed39da0a charles.park     2018-06-01   81  
cd221c7b638f83 Eduardo Valentin 2016-11-07   82  int thermal_zone_get_temp(struct thermal_zone_device *tz, int *temp)
cd221c7b638f83 Eduardo Valentin 2016-11-07   83  {
cd221c7b638f83 Eduardo Valentin 2016-11-07   84  	int ret = -EINVAL;
cd221c7b638f83 Eduardo Valentin 2016-11-07   85  	int count;
cd221c7b638f83 Eduardo Valentin 2016-11-07   86  	int crit_temp = INT_MAX;
cd221c7b638f83 Eduardo Valentin 2016-11-07   87  	enum thermal_trip_type type;
cd221c7b638f83 Eduardo Valentin 2016-11-07   88  
cd221c7b638f83 Eduardo Valentin 2016-11-07   89  	if (!tz || IS_ERR(tz) || !tz->ops->get_temp)
cd221c7b638f83 Eduardo Valentin 2016-11-07   90  		goto exit;
cd221c7b638f83 Eduardo Valentin 2016-11-07   91  
cd221c7b638f83 Eduardo Valentin 2016-11-07   92  	mutex_lock(&tz->lock);
cd221c7b638f83 Eduardo Valentin 2016-11-07   93  
cd221c7b638f83 Eduardo Valentin 2016-11-07   94  	ret = tz->ops->get_temp(tz, temp);
cd221c7b638f83 Eduardo Valentin 2016-11-07   95  
cd221c7b638f83 Eduardo Valentin 2016-11-07   96  	if (IS_ENABLED(CONFIG_THERMAL_EMULATION) && tz->emul_temperature) {
cd221c7b638f83 Eduardo Valentin 2016-11-07   97  		for (count = 0; count < tz->trips; count++) {
cd221c7b638f83 Eduardo Valentin 2016-11-07   98  			ret = tz->ops->get_trip_type(tz, count, &type);
cd221c7b638f83 Eduardo Valentin 2016-11-07   99  			if (!ret && type == THERMAL_TRIP_CRITICAL) {
cd221c7b638f83 Eduardo Valentin 2016-11-07  100  				ret = tz->ops->get_trip_temp(tz, count,
cd221c7b638f83 Eduardo Valentin 2016-11-07  101  						&crit_temp);
cd221c7b638f83 Eduardo Valentin 2016-11-07  102  				break;
cd221c7b638f83 Eduardo Valentin 2016-11-07  103  			}
cd221c7b638f83 Eduardo Valentin 2016-11-07  104  		}
cd221c7b638f83 Eduardo Valentin 2016-11-07  105  
cd221c7b638f83 Eduardo Valentin 2016-11-07  106  		/*
cd221c7b638f83 Eduardo Valentin 2016-11-07  107  		 * Only allow emulating a temperature when the real temperature
cd221c7b638f83 Eduardo Valentin 2016-11-07  108  		 * is below the critical temperature so that the emulation code
cd221c7b638f83 Eduardo Valentin 2016-11-07  109  		 * cannot hide critical conditions.
cd221c7b638f83 Eduardo Valentin 2016-11-07  110  		 */
cd221c7b638f83 Eduardo Valentin 2016-11-07  111  		if (!ret && *temp < crit_temp)
cd221c7b638f83 Eduardo Valentin 2016-11-07  112  			*temp = tz->emul_temperature;
cd221c7b638f83 Eduardo Valentin 2016-11-07  113  	}
cd221c7b638f83 Eduardo Valentin 2016-11-07  114  
26ef3eed39da0a charles.park     2018-06-01  115  	/* save thermal_zone data */
26ef3eed39da0a charles.park     2018-06-01  116  	if (!ret)
26ef3eed39da0a charles.park     2018-06-01  117  		thermal_zone_data[tz->id] = *temp;
26ef3eed39da0a charles.park     2018-06-01  118  	/*
26ef3eed39da0a charles.park     2018-06-01  119  	 * This case is that the thermal sensor is broken.
26ef3eed39da0a charles.park     2018-06-01  120  	 * That's not real temperature. Set the fake temperature value in order to
26ef3eed39da0a charles.park     2018-06-01  121  	 * avoid reaching the ciritical temperature.
26ef3eed39da0a charles.park     2018-06-01  122  	 */
26ef3eed39da0a charles.park     2018-06-01 @123  	if ((thermal_zone_data[tz->id] > CRITICAL_TEMP) && (tz->id != 4)) {
26ef3eed39da0a charles.park     2018-06-01  124  		int i, broken_sensor = 0, correct_temp = 0;
26ef3eed39da0a charles.park     2018-06-01  125  		for (i = 0; i < 4; i++) {
26ef3eed39da0a charles.park     2018-06-01  126  			if ((thermal_zone_data[i] <= CRITICAL_TEMP) &&
26ef3eed39da0a charles.park     2018-06-01  127  			    (correct_temp <= thermal_zone_data[i]))
26ef3eed39da0a charles.park     2018-06-01  128  				correct_temp = thermal_zone_data[i];
26ef3eed39da0a charles.park     2018-06-01  129  			if (thermal_zone_data[i] > CRITICAL_TEMP)
26ef3eed39da0a charles.park     2018-06-01  130  				broken_sensor++;
26ef3eed39da0a charles.park     2018-06-01  131  		}
26ef3eed39da0a charles.park     2018-06-01  132  		/*
26ef3eed39da0a charles.park     2018-06-01  133  		 * if all thermal sensor broken then critical temperature data send
26ef3eed39da0a charles.park     2018-06-01  134  		 * for system poweroff.
26ef3eed39da0a charles.park     2018-06-01  135  		 */
26ef3eed39da0a charles.park     2018-06-01  136  		*temp = (broken_sensor == 4) ? CRITICAL_TEMP : correct_temp;
26ef3eed39da0a charles.park     2018-06-01  137  	}
26ef3eed39da0a charles.park     2018-06-01  138  
cd221c7b638f83 Eduardo Valentin 2016-11-07  139  	mutex_unlock(&tz->lock);
cd221c7b638f83 Eduardo Valentin 2016-11-07  140  exit:
cd221c7b638f83 Eduardo Valentin 2016-11-07  141  	return ret;
cd221c7b638f83 Eduardo Valentin 2016-11-07  142  }
cd221c7b638f83 Eduardo Valentin 2016-11-07  143  EXPORT_SYMBOL_GPL(thermal_zone_get_temp);
cd221c7b638f83 Eduardo Valentin 2016-11-07  144  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 30723 bytes --]

             reply	other threads:[~2020-09-03 16:32 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-03 16:32 kernel test robot [this message]
  -- strict thread matches above, loose matches on Subject: below --
2020-09-04  6:52 [tobetter-linux:odroid-5.9.y 66/69] drivers/thermal/thermal_helpers.c:123 thermal_zone_get_temp() error: testing array offset 'tz->id' after use Dan Carpenter
2020-09-04  6:52 ` Dan Carpenter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=202009040050.QkhqDHSK%lkp@intel.com \
    --to=lkp@intel.com \
    --cc=kbuild@lists.01.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.