From: Takashi Iwai <tiwai@suse.de>
To: "Geoffrey D. Bennett" <g@b4.vu>
Cc: Takashi Iwai <tiwai@suse.de>, Jaroslav Kysela <perex@perex.cz>,
Takashi Iwai <tiwai@suse.com>,
linux-sound@vger.kernel.org
Subject: Re: [PATCH v6 1/2] ALSA: FCP: Add Focusrite Control Protocol driver
Date: Tue, 14 Jan 2025 13:57:38 +0100 [thread overview]
Message-ID: <87h661zh6l.wl-tiwai@suse.de> (raw)
In-Reply-To: <df86969ea91cd2a3dd07c0c63c00c5b97a4d8485.1736792486.git.g@b4.vu>
On Mon, 13 Jan 2025 20:42:01 +0100,
Geoffrey D. Bennett wrote:
> +static int fcp_meter_ctl_get(struct snd_kcontrol *kctl,
> + struct snd_ctl_elem_value *ucontrol)
> +{
> + struct usb_mixer_elem_info *elem = kctl->private_data;
> + struct usb_mixer_interface *mixer = elem->head.mixer;
> + struct fcp_data *private = mixer->private_data;
> + int num_meter_slots, resp_size;
> + u32 *resp __free(kfree) = NULL;
> + int i, err = 0;
> +
> + struct {
> + __le16 pad;
> + __le16 num_meters;
> + __le32 magic;
> + } __packed req;
> +
> + guard(mutex)(&private->mutex);
> +
> + num_meter_slots = private->num_meter_slots;
> + resp_size = num_meter_slots * sizeof(u32);
> +
> + resp = kmalloc(resp_size, GFP_KERNEL);
> + if (!resp)
> + return -ENOMEM;
> +
> + req.pad = 0;
> + req.num_meters = cpu_to_le16(num_meter_slots);
> + req.magic = cpu_to_le32(FCP_USB_METER_LEVELS_GET_MAGIC);
> + err = fcp_usb(mixer, FCP_USB_GET_METER,
> + &req, sizeof(req), resp, resp_size);
> +
> + /* reinit and retry if needed */
> + if (err == -ENODEV) {
> + err = fcp_reinit(mixer);
> + if (err < 0)
> + return err;
> + err = fcp_usb(mixer, FCP_USB_GET_METER,
> + &req, sizeof(req), resp, resp_size);
> + } else if (err < 0) {
> + return err;
> + }
You seem to have forgotten to check the error after the second
fcp_usb()?
I think fcp_reinit() can be better checked before the first fcb_usb()
call, just by checking mixer->urb. i.e.
if (!mixer->urb) {
err = fcp_reinit(mixer);
if (err < 0)
return err;
}
err = fcp_usb(...);
if (err < 0)
return err;
Or change fcp_reinit() to return 0 if mixer->urbs is already set, then
you can call fcp_reinit() unconditionally, too.
> +/* Execute an FCP command specified by the user */
> +static int fcp_ioctl_cmd(struct usb_mixer_interface *mixer,
> + struct fcp_cmd __user *arg)
> +{
(snip)
> + /* copy response to user */
> + if (cmd.resp_size > 0)
> + if (copy_to_user(((void __user *)arg) + sizeof(cmd), data,
> + cmd.resp_size))
This should be
if (copy_to_user(arg->data, data, cmd.resp_size))
(snip)
> +/* Set the Level Meter map and add the control */
> +static int fcp_ioctl_set_meter_map(struct usb_mixer_interface *mixer,
> + unsigned long arg)
> +{
> + struct fcp_meter_map map;
> + struct fcp_data *private = mixer->private_data;
> + s16 *tmp_map __free(kfree) = NULL;
> + int err;
> +
> + if (copy_from_user(&map, (void __user *)arg, sizeof(map)))
This function can also take struct fcp_meter_map __user * argument,
and you can avoid the cast.
Ditto for fcp_ioctl_init().
> +static int fcp_hwdep_ioctl(struct snd_hwdep *hw, struct file *file,
> + unsigned int cmd, unsigned long arg)
> +{
> + struct usb_mixer_interface *mixer = hw->private_data;
> + struct fcp_data *private = mixer->private_data;
You can assign a void __user pointer, e.g.
void __user *argp = (void __user *)arg;
and pass it to each function, e.g.
> + guard(mutex)(&private->mutex);
> +
> + switch (cmd) {
> +
> + case FCP_IOCTL_PVERSION:
> + return put_user(FCP_HWDEP_VERSION,
> + (int __user *)arg) ? -EFAULT : 0;
> + break;
> +
> + case FCP_IOCTL_INIT:
> + return fcp_ioctl_init(mixer, arg);
This will be:
return fcp_ioctl_init(mixer, argp);
and make fcp_ioctl_init() receiving it like:
static int fcp_ioctl_init(struct usb_mixer_interface *mixer,
struct fcp_init __user *arg)
{
struct fcp_init init;
....
if (copy_from_user(&init, arg, sizeof(init)))
return -EFAULT;
....
if (copy_to_user(arg->resp, resp, buf_size))
return -EFAULT;
Takashi
next prev parent reply other threads:[~2025-01-14 12:57 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-13 19:41 [PATCH v6 0/2] ALSA: Add driver for big Scarlett 4th Gen interfaces Geoffrey D. Bennett
2025-01-13 19:42 ` [PATCH v6 1/2] ALSA: FCP: Add Focusrite Control Protocol driver Geoffrey D. Bennett
2025-01-14 12:57 ` Takashi Iwai [this message]
2025-01-13 19:42 ` [PATCH v6 2/2] ALSA: scarlett2: Add device_setup option to use FCP driver Geoffrey D. Bennett
2025-01-14 12:43 ` [PATCH v6 0/2] ALSA: Add driver for big Scarlett 4th Gen interfaces Takashi Iwai
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=87h661zh6l.wl-tiwai@suse.de \
--to=tiwai@suse.de \
--cc=g@b4.vu \
--cc=linux-sound@vger.kernel.org \
--cc=perex@perex.cz \
--cc=tiwai@suse.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox