All of lore.kernel.org
 help / color / mirror / Atom feed
From: Piergiorgio Beruto <piergiorgio.beruto@gmail.com>
To: Dan Carpenter <error27@gmail.com>
Cc: kernel-janitors@vger.kernel.org
Subject: Re: [bug report] drivers/net/phy: add helpers to get/set PLCA configuration
Date: Tue, 17 Jan 2023 00:11:56 +0100	[thread overview]
Message-ID: <Y8XZvO6FC0QKycDE@gvm01> (raw)
In-Reply-To: <Y8UiT9AKQIqz1zxr@kili>

On Mon, Jan 16, 2023 at 01:09:19PM +0300, Dan Carpenter wrote:
> Hello Piergiorgio Beruto,
> 
> The patch 493323416fed: "drivers/net/phy: add helpers to get/set PLCA
> configuration" from Jan 9, 2023, leads to the following Smatch static
> checker warning:
> 
> 	drivers/net/phy/phy-c45.c:1036 genphy_c45_plca_set_cfg()
> 	error: uninitialized symbol 'val'.
> 
> drivers/net/phy/phy-c45.c
>    999  int genphy_c45_plca_set_cfg(struct phy_device *phydev,
>   1000                              const struct phy_plca_cfg *plca_cfg)
>   1001  {
>   1002          int ret;
>   1003          u16 val;
>   1004  
>   1005          // PLCA IDVER is read-only
>   1006          if (plca_cfg->version >= 0)
>   1007                  return -EINVAL;
>   1008  
>   1009          // first of all, disable PLCA if required
>   1010          if (plca_cfg->enabled == 0) {
>   1011                  ret = phy_clear_bits_mmd(phydev, MDIO_MMD_VEND2,
>   1012                                           MDIO_OATC14_PLCA_CTRL0,
>   1013                                           MDIO_OATC14_PLCA_EN);
>   1014  
>   1015                  if (ret < 0)
>   1016                          return ret;
>   1017          }
>   1018  
>   1019          // check if we need to set the PLCA node count, node ID, or both
>   1020          if (plca_cfg->node_cnt >= 0 || plca_cfg->node_id >= 0) {
> 
> Let's assume both conditions are true
> 
>   1021                  /* if one between node count and node ID is -not- to be
>   1022                   * changed, read the register to later perform merge/purge of
>   1023                   * the configuration as appropriate
>   1024                   */
>   1025                  if (plca_cfg->node_cnt < 0 || plca_cfg->node_id < 0) {
> 
> Then neither condition is true here
> 
>   1026                          ret = phy_read_mmd(phydev, MDIO_MMD_VEND2,
>   1027                                             MDIO_OATC14_PLCA_CTRL1);
>   1028  
>   1029                          if (ret < 0)
>   1030                                  return ret;
>   1031  
>   1032                          val = ret;
>   1033                  }
>   1034  
>   1035                  if (plca_cfg->node_cnt >= 0)
>   1036                          val = (val & ~MDIO_OATC14_PLCA_NCNT) |
>                                        ^^^
> Uninitialized
This is correct, however it is not a real problem. Please, allow me to
explain. If both conditions are true (initially) then both conditions at
lines 1035 and 1039 will be true as well. This means that the content of
'val' is completely overwritten with the content of node_cnt and
node_id. This is because the register is 16 bits and node_cnt/id are 8
bits each. Therefore, regardless of the initial status of 'val', its
content is fully determines after line 1039.

With that said, I have no issues in initializing val to 0 if you think
it's still worth it after my explanation.
> 
>   1037                                (plca_cfg->node_cnt << 8);
>   1038  
>   1039                  if (plca_cfg->node_id >= 0)
>   1040                          val = (val & ~MDIO_OATC14_PLCA_ID) |
>   1041                                (plca_cfg->node_id);
> 
> 
> regards,
> dan carpenter
Thank you very much for reporting this,
Kind Regards,
Piergiorgio


  reply	other threads:[~2023-01-16 23:20 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-16 10:09 [bug report] drivers/net/phy: add helpers to get/set PLCA configuration Dan Carpenter
2023-01-16 23:11 ` Piergiorgio Beruto [this message]
2023-01-17  3:46   ` 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=Y8XZvO6FC0QKycDE@gvm01 \
    --to=piergiorgio.beruto@gmail.com \
    --cc=error27@gmail.com \
    --cc=kernel-janitors@vger.kernel.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.