All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: roger.lu@mediatek.com
Cc: linux-mediatek@lists.infradead.org, kernel-janitors@vger.kernel.org
Subject: [bug report] soc: mediatek: SVS: add mt8192 SVS GPU driver
Date: Wed, 22 Jun 2022 09:47:34 +0300	[thread overview]
Message-ID: <YrK7BkMp5zbgziBq@kili> (raw)

Hello Roger Lu,

The patch 0bbb09b2af9d: "soc: mediatek: SVS: add mt8192 SVS GPU
driver" from May 16, 2022, leads to the following (unpublished) Smatch
static checker warning:

	drivers/soc/mediatek/mtk-svs.c:532 svs_adjust_pm_opp_volts()
	warn: loop overwrites return value 'ret'

drivers/soc/mediatek/mtk-svs.c
    487 static int svs_adjust_pm_opp_volts(struct svs_bank *svsb)
    488 {
    489         int ret = -EPERM, tzone_temp = 0;
                    ^^^^^^^^^^^^^
What is this -EPERM for?

    490         u32 i, svsb_volt, opp_volt, temp_voffset = 0, opp_start, opp_stop;
    491 
    492         mutex_lock(&svsb->lock);
    493 
    494         /*
    495          * 2-line bank updates its corresponding opp volts.
    496          * 1-line bank updates all opp volts.
    497          */
    498         if (svsb->type == SVSB_HIGH) {
    499                 opp_start = 0;
    500                 opp_stop = svsb->turn_pt;
    501         } else if (svsb->type == SVSB_LOW) {
    502                 opp_start = svsb->turn_pt;
    503                 opp_stop = svsb->opp_count;
    504         } else {
    505                 opp_start = 0;
    506                 opp_stop = svsb->opp_count;
    507         }
    508 
    509         /* Get thermal effect */
    510         if (svsb->phase == SVSB_PHASE_MON) {
    511                 ret = thermal_zone_get_temp(svsb->tzd, &tzone_temp);
    512                 if (ret || (svsb->temp > SVSB_TEMP_UPPER_BOUND &&
    513                             svsb->temp < SVSB_TEMP_LOWER_BOUND)) {
    514                         dev_err(svsb->dev, "%s: %d (0x%x), run default volts\n",
    515                                 svsb->tzone_name, ret, svsb->temp);
    516                         svsb->phase = SVSB_PHASE_ERROR;

ret is set here but there is no goto unlock_mutex;

    517                 }
    518 
    519                 if (tzone_temp >= svsb->tzone_htemp)
    520                         temp_voffset += svsb->tzone_htemp_voffset;
    521                 else if (tzone_temp <= svsb->tzone_ltemp)
    522                         temp_voffset += svsb->tzone_ltemp_voffset;
    523 
    524                 /* 2-line bank update all opp volts when running mon mode */
    525                 if (svsb->type == SVSB_HIGH || svsb->type == SVSB_LOW) {
    526                         opp_start = 0;
    527                         opp_stop = svsb->opp_count;
    528                 }
    529         }
    530 
    531         /* vmin <= svsb_volt (opp_volt) <= default opp voltage */
--> 532         for (i = opp_start; i < opp_stop; i++) {

I guess the bug is that there was supposed to be an explicit check?

	if (opp_start == opp_stop) {
		ret = -EPERM;
		goto unlock_mutex;
	}

Otherwise, we are possibly returning the ret from the /* Get thermal
effect */ block.

    533                 switch (svsb->phase) {
    534                 case SVSB_PHASE_ERROR:
    535                         opp_volt = svsb->opp_dvolt[i];
    536                         break;
    537                 case SVSB_PHASE_INIT01:
    538                         /* do nothing */
    539                         goto unlock_mutex;
    540                 case SVSB_PHASE_INIT02:
    541                         svsb_volt = max(svsb->volt[i], svsb->vmin);
    542                         opp_volt = svs_bank_volt_to_opp_volt(svsb_volt,
    543                                                              svsb->volt_step,
    544                                                              svsb->volt_base);
    545                         break;
    546                 case SVSB_PHASE_MON:
    547                         svsb_volt = max(svsb->volt[i] + temp_voffset, svsb->vmin);
    548                         opp_volt = svs_bank_volt_to_opp_volt(svsb_volt,
    549                                                              svsb->volt_step,
    550                                                              svsb->volt_base);
    551                         break;
    552                 default:
    553                         dev_err(svsb->dev, "unknown phase: %u\n", svsb->phase);
    554                         ret = -EINVAL;
    555                         goto unlock_mutex;
    556                 }
    557 
    558                 opp_volt = min(opp_volt, svsb->opp_dvolt[i]);
    559                 ret = dev_pm_opp_adjust_voltage(svsb->opp_dev,
    560                                                 svsb->opp_dfreq[i],
    561                                                 opp_volt, opp_volt,
    562                                                 svsb->opp_dvolt[i]);
    563                 if (ret) {
    564                         dev_err(svsb->dev, "set %uuV fail: %d\n",
    565                                 opp_volt, ret);
    566                         goto unlock_mutex;
    567                 }
    568         }
    569 
    570 unlock_mutex:
    571         mutex_unlock(&svsb->lock);
    572 
    573         return ret;
    574 }

regards,
dan carpenter

             reply	other threads:[~2022-06-22  6:48 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-22  6:47 Dan Carpenter [this message]
2022-06-22  9:18 ` [bug report] soc: mediatek: SVS: add mt8192 SVS GPU driver Roger Lu (陸瑞傑)
2022-06-22  9:34   ` 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=YrK7BkMp5zbgziBq@kili \
    --to=dan.carpenter@oracle.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=roger.lu@mediatek.com \
    /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.