From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Peng Fan <peng.fan@nxp.com>,
linux-can@vger.kernel.org, linux-phy@lists.infradead.org,
linux-kernel@vger.kernel.org
Cc: Marc Kleine-Budde <mkl@pengutronix.de>,
Vincent Mailhol <mailhol@kernel.org>,
Vinod Koul <vkoul@kernel.org>,
Neil Armstrong <neil.armstrong@linaro.org>,
Josua Mayer <josua@solid-run.com>, Ulf Hansson <ulfh@kernel.org>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Subject: [PATCH v5 5/6] phy: phy-can-transceiver: Decouple assignment and definition in probe
Date: Thu, 14 May 2026 00:01:30 +0200 [thread overview]
Message-ID: <20260513220336.369628-6-andriy.shevchenko@linux.intel.com> (raw)
In-Reply-To: <20260513220336.369628-1-andriy.shevchenko@linux.intel.com>
The code like
int foo = X;
...
if (bar)
foo = Y;
is prone to subtle mistakes and hence harder to maintain as the foo value
may be changed inadvertently while code in '...' grown in lines. On top
it's harder to navigate to understand the possible values of foo when branch
is not taken (requires to look somewhere else in the code, far from the piece
at hand).
Besides that in case of taken branch the foo will be rewritten, which is
not a problem per se, just an unneeded operation.
Decouple assignment and definition to use if-else to address the inconveniences
described above.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/phy/phy-can-transceiver.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/phy/phy-can-transceiver.c b/drivers/phy/phy-can-transceiver.c
index 3cebaa54f7db..30330499585b 100644
--- a/drivers/phy/phy-can-transceiver.c
+++ b/drivers/phy/phy-can-transceiver.c
@@ -128,8 +128,8 @@ static int can_transceiver_phy_probe(struct platform_device *pdev)
struct gpio_desc *standby_gpio;
struct gpio_desc *enable_gpio;
struct mux_state *mux_state;
- int err, i, num_ch = 1;
const char *propname;
+ int err, i, num_ch;
u32 max_bitrate;
drvdata = device_get_match_data(dev);
@@ -138,6 +138,8 @@ static int can_transceiver_phy_probe(struct platform_device *pdev)
if (drvdata->flags & CAN_TRANSCEIVER_DUAL_CH)
num_ch = 2;
+ else
+ num_ch = 1;
priv = devm_kzalloc(dev, struct_size(priv, can_transceiver_phy, num_ch), GFP_KERNEL);
if (!priv)
--
2.50.1
next prev parent reply other threads:[~2026-05-13 22:03 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-13 22:01 [PATCH v5 0/6] phy: phy-can-transceiver: Ad-hoc cleanups and refactoring Andy Shevchenko
2026-05-13 22:01 ` [PATCH v5 1/6] phy: phy-can-transceiver: Check driver match and driver data against NULL Andy Shevchenko
2026-05-13 22:01 ` [PATCH v5 2/6] phy: phy-can-transceiver: use device_get_match_data() Andy Shevchenko
2026-05-13 22:01 ` [PATCH v5 3/6] phy: phy-can-transceiver: Move OF ID table closer to their user Andy Shevchenko
2026-05-13 22:01 ` [PATCH v5 4/6] phy: phy-can-transceiver: Don't check for specific errors when parsing properties Andy Shevchenko
2026-05-13 22:01 ` Andy Shevchenko [this message]
2026-05-13 22:01 ` [PATCH v5 6/6] phy: phy-can-transceiver: Drop unused include Andy Shevchenko
2026-05-14 16:17 ` [PATCH v5 0/6] phy: phy-can-transceiver: Ad-hoc cleanups and refactoring Vinod Koul
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=20260513220336.369628-6-andriy.shevchenko@linux.intel.com \
--to=andriy.shevchenko@linux.intel.com \
--cc=josua@solid-run.com \
--cc=linux-can@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-phy@lists.infradead.org \
--cc=mailhol@kernel.org \
--cc=mkl@pengutronix.de \
--cc=neil.armstrong@linaro.org \
--cc=peng.fan@nxp.com \
--cc=ulfh@kernel.org \
--cc=vkoul@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox