All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Svyatoslav Ryhel" <clamor95@gmail.com>
Cc: linux-sound@vger.kernel.org, devicetree@vger.kernel.org,
	robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v3 2/2] ASoC: codecs: Add support for Fortemedia FM34NE DSP
Date: Tue, 27 Oct 2026 11:48:44 +0000	[thread overview]
Message-ID: <sashiko-outbox-186477@kernel.org> (raw)
In-Reply-To: <20261027113929.65102-3-clamor95@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] ASoC: fm34ne-dsp: mixing guard() and goto cleanup in fm34ne_dsp_set_config()
--

commit 49a97b167b8daf22a65a613318793960938a84f4
Author: Svyatoslav Ryhel <clamor95@gmail.com>

ASoC: codecs: Add support for Fortemedia FM34NE DSP

This commit adds an ASoC codec driver for the Fortemedia FM34NE digital sound
processing chip used for active noise suppression on ASUS Transformer
devices.

> diff --git a/sound/soc/codecs/fm34ne-dsp.c b/sound/soc/codecs/fm34ne-dsp.c
> new file mode 100644
> index 0000000000000..07f22507a53df
> --- /dev/null
> +++ b/sound/soc/codecs/fm34ne-dsp.c
> @@ -0,0 +1,386 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +
> +#include <linux/clk.h>
> +#include <linux/delay.h>
> +#include <linux/gpio/consumer.h>
> +#include <linux/i2c.h>
> +#include <linux/module.h>
> +#include <linux/property.h>
> +#include <linux/regulator/consumer.h>
> +
> +#include <sound/core.h>
> +#include <sound/soc.h>
> +
> +#include "fm34ne-dsp.h"
> +
> +struct fm34ne_dsp {
> +	struct i2c_client *client;
> +
> +	struct gpio_desc *bypass_gpio;
> +	struct gpio_desc *reset_gpio;
> +
> +	struct clk *dap_mclk;
> +	struct regulator *vdd_supply;
> +	struct mutex lock; /* prevent simultaneous parameter writing */
> +
> +	const struct fm34ne_dsp_info *info;
> +};
> +
> +static int fm34ne_dsp_set_config(struct fm34ne_dsp *dsp, enum dsp_state state)
> +{
> +	struct device *dev = &dsp->client->dev;
> +	int ret;
> +
> +	guard(mutex)(&dsp->lock);
> +
> +	gpiod_set_value_cansleep(dsp->bypass_gpio, 1);
> +	msleep(20);
> +
> +	switch (state) {
> +	case FM34NE_NS_ENABLE:
> +		ret = i2c_master_send(dsp->client, dsp->info->enable_parameter,
> +				      dsp->info->enable_parameter_length);
> +		if (ret < 0) {
> +			dev_err(dev, "Failed to set DSP enable %d\n", ret);
> +			goto exit;
> +		}
> +
> +		ret = i2c_master_send(dsp->client, dsp->info->enable_noise_suppression,
> +				      dsp->info->enable_ns_length);
> +		if (ret < 0) {
> +			dev_err(dev, "Failed to enable DSP noise suppression %d\n", ret);
> +			goto exit;
> +		}
> +
> +		break;
> +
> +	case FM34NE_NS_DISABLE:
> +		ret = i2c_master_send(dsp->client, dsp->info->enable_parameter,
> +				      dsp->info->enable_parameter_length);
> +		if (ret < 0) {
> +			dev_err(dev, "Failed to set DSP enable with %d\n", ret);
> +			goto exit;
> +		}
> +
> +		ret = i2c_master_send(dsp->client, dsp->info->disable_noise_suppression,
> +				      dsp->info->disable_ns_length);
> +		if (ret < 0) {
> +			dev_err(dev, "Failed to disable DSP noise suppression with %d\n", ret);
> +			goto exit;
> +		}
> +
> +		break;
> +
> +	case FM34NE_BYPASS:
> +	default:
> +		ret = i2c_master_send(dsp->client, bypass_parameter, sizeof(bypass_parameter));
> +		if (ret < 0) {
> +			dev_err(dev, "Failed to set DSP bypass with %d\n", ret);
> +			goto exit;
> +		}
> +
> +		break;
> +	}
> +
> +exit:
> +	gpiod_set_value_cansleep(dsp->bypass_gpio, 0);
> +
> +	if (ret < 0)
> +		return ret;
> +
> +	return 0;
> +}

[Severity: Low]
In fm34ne_dsp_set_config(), dsp->lock is acquired via guard(mutex)(&dsp->lock)
while i2c_master_send() failure paths jump to the exit label using goto exit
to deassert dsp->bypass_gpio.

The cleanup rules in include/linux/cleanup.h state that goto-based cleanup
and scope-based cleanup helpers like guard() should not be mixed in the same
function:

 * Lastly, given that the benefit of cleanup helpers is removal of
 * "goto", and that the "goto" statement can jump between scopes, the
 * expectation is that usage of "goto" and cleanup helpers is never
 * mixed in the same function. I.e. for a given routine, convert all
 * resources that need a "goto" cleanup to scope-based cleanup, or
 * convert none of them.

Also, sound/soc/codecs/fm34ne-dsp.c uses guard(mutex) and struct mutex
without explicitly including linux/cleanup.h and linux/mutex.h.

Could fm34ne_dsp_set_config() avoid mixing guard(mutex) with goto exit
(for example by using break from the switch statement or a helper function
for the I2C transfers), and include linux/cleanup.h and linux/mutex.h
explicitly?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261027113929.65102-1-clamor95@gmail.com?part=2

      reply	other threads:[~2026-10-27 11:48 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-27 11:39 [PATCH v3 0/2] ASoC: codecs: Add support for Fortemedia FM34NE DSP Svyatoslav Ryhel
2026-10-27 11:39 ` [PATCH v3 1/2] ASoC: dt-bindings: Document " Svyatoslav Ryhel
2026-10-27 11:39 ` [PATCH v3 2/2] ASoC: codecs: Add support for Fortemedia " Svyatoslav Ryhel
2026-10-27 11:48   ` sashiko-bot [this message]

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=sashiko-outbox-186477@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=clamor95@gmail.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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.