From: Oliver Neukum <oneukum@suse.com>
To: "David R. Bild" <david.bild@xaptum.com>,
Peter Huewe <peterhuewe@gmx.de>,
Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-integrity@vger.kernel.org, linux-usb@vger.kernel.org
Subject: Re: [PATCH v3 1/2] usb: misc: xapea00x: add driver for Xaptum ENF Access Card
Date: Mon, 07 May 2018 11:58:48 +0200 [thread overview]
Message-ID: <1525687128.24345.3.camel@suse.com> (raw)
In-Reply-To: <20180504130022.5231-2-david.bild@xaptum.com>
Am Freitag, den 04.05.2018, 08:00 -0500 schrieb David R. Bild :
>
> +config USB_XAPEA00X
> + tristate "Xaptum ENF Access card support (XAP-EA-00x)"
> + depends on USB_SUPPORT && SPI && TCG_TPM
You'd have to know how the device internally works. It would be better
to select SPI.
> +static int xapea00x_br_bulk_write(struct xapea00x_device *dev,
> + struct xapea00x_br_bulk_command *header,
> + const void *data, int len)
> +{
> + u8 *buf;
> + unsigned int pipe;
> + int buf_len, actual_len, retval;
> +
> + buf_len = sizeof(struct xapea00x_br_bulk_command) + len;
> + buf = kzalloc(buf_len, GFP_KERNEL);
> + if (!buf) {
> + retval = -ENOMEM;
> + goto out;
> + }
> +
> + memcpy(buf, header, sizeof(struct xapea00x_br_bulk_command));
> + memcpy(buf + sizeof(struct xapea00x_br_bulk_command), data, len);
> +
> + pipe = usb_sndbulkpipe(dev->udev, dev->bulk_out->bEndpointAddress);
> + retval = usb_bulk_msg(dev->udev, pipe, buf, buf_len, &actual_len,
> + XAPEA00X_BR_USB_TIMEOUT);
> + if (retval)
> + goto free_buf;
WTF?
> +free_buf:
> + kzfree(buf);
> +
> +out:
> + return retval;
> +}
> +
[..]
> +static int xapea00x_spi_setup(struct spi_device *spi)
> +{
> + struct xapea00x_device *dev;
> + int retval;
> +
> + dev = spi_master_get_devdata(spi->master);
> +
> + mutex_lock(&dev->usb_mutex);
> + if (!dev->interface) {
> + retval = -ENODEV;
> + goto out;
> + }
> +
> + /* Verify that this is the TPM device */
> + if (spi->chip_select != 0) {
> + retval = -EINVAL;
> + goto err;
> + }
> +
> + /*
> + * Disable auto chip select for the TPM channel.
> + * Must be done after setting the SPI parameters.
> + */
> + retval = xapea00x_br_disable_cs(dev, 0);
> + if (retval)
> + goto err;
> +
> + /* De-assert chip select for the TPM channel. */
> + retval = xapea00x_br_deassert_cs(dev, 0);
> + if (retval)
> + goto err;
> +
> + goto out;
> +
> +err:
> + dev_err(&dev->interface->dev,
> + "configuring SPI channel failed with %d\n", retval);
That could be a simple 'if' statement.
> +
> +out:
> + mutex_unlock(&dev->usb_mutex);
> + return retval;
> +}
> +
>
[..]
> +/**
> + * xapea00x_spi_probe - Register and configure the SPI master.
> + * @dev: the device whose SPI master to register
> + *
> + * Return: If successful, 0. Otherwise a negative error number.
> + */
> +static int xapea00x_spi_probe(struct xapea00x_device *dev)
> +{
> + struct spi_master *spi_master;
> + int retval;
> +
> + spi_master = spi_alloc_master(&dev->interface->dev, sizeof(void *));
> + if (!spi_master) {
> + retval = -ENOMEM;
> + goto err_out;
> + }
> +
> + spi_master_set_devdata(spi_master, dev);
> +
> + spi_master->min_speed_hz = 93 * 1000 + 800; /* 93.9kHz */
> + spi_master->max_speed_hz = 12 * 1000 * 1000; /* 12 MHz */
> +
> + spi_master->bus_num = -1; /* dynamically assigned */
> + spi_master->num_chipselect = 1;
> + spi_master->mode_bits = SPI_MODE_0;
> +
> + spi_master->flags = 0;
> + spi_master->setup = xapea00x_spi_setup;
> + spi_master->transfer_one_message = xapea00x_spi_transfer_one_message;
> +
> + retval = spi_register_master(spi_master);
> +
> + if (retval)
> + goto free_spi;
> +
> + dev->spi_master = spi_master;
Race condition.
> +
> + return 0;
> +
> +free_spi:
> + spi_master_put(spi_master);
> + dev->spi_master = NULL;
> +
> +err_out:
> + return retval;
> +}
> +
> +struct xapea00x_async_probe {
> + struct work_struct work;
> + struct xapea00x_device *dev;
> +};
> +
> +#define work_to_probe(w) container_of(w, struct xapea00x_async_probe, work)
> +
> +/**
> + * xapea00x_init_async_probe - initialize an async probe with the
> + * specified values.
> + * @probe: pointer to the async_probe to initialize
> + * @dev: pointer to the device to probe
> + * @f: pointer to the probe function
> + */
> +static void xapea00x_init_async_probe(struct xapea00x_async_probe *probe,
> + struct xapea00x_device *dev,
> + void (*f)(struct work_struct *work))
> +{
> + INIT_WORK(&probe->work, f);
> + probe->dev = dev;
> +
> + kref_get(&dev->kref);
> + spi_master_get(dev->spi_master);
> +}
> +
> +/**
> + * xapea00x_cleanup_async_probe - clean up the internals of the async
> + * probe. Call this method after the probe has completed.
> + *
> + * The caller is responsible for freeing the probe itself, if
> + * dynamically allocated.
> + *
> + * @probe: pointer to the async_probe to clean up
> + */
> +static void xapea00x_cleanup_async_probe(struct xapea00x_async_probe *probe)
> +{
> + spi_master_put(probe->dev->spi_master);
> + kref_put(&probe->dev->kref, xapea00x_delete);
> +}
> +
> +static struct spi_board_info tpm_board_info = {
> + .modalias = XAPEA00X_TPM_MODALIAS,
> + .max_speed_hz = 43 * 1000 * 1000, // Hz
Are you hardcoding HZ ?
> + .chip_select = 0,
> + .mode = SPI_MODE_0
> +};
Regards
Oliver
WARNING: multiple messages have this Message-ID (diff)
From: Oliver Neukum <oneukum@suse.com>
To: "David R. Bild" <david.bild@xaptum.com>,
Peter Huewe <peterhuewe@gmx.de>,
Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-integrity@vger.kernel.org, linux-usb@vger.kernel.org
Subject: [v3,1/2] usb: misc: xapea00x: add driver for Xaptum ENF Access Card
Date: Mon, 07 May 2018 11:58:48 +0200 [thread overview]
Message-ID: <1525687128.24345.3.camel@suse.com> (raw)
Am Freitag, den 04.05.2018, 08:00 -0500 schrieb David R. Bild :
>
> +config USB_XAPEA00X
> + tristate "Xaptum ENF Access card support (XAP-EA-00x)"
> + depends on USB_SUPPORT && SPI && TCG_TPM
You'd have to know how the device internally works. It would be better
to select SPI.
> +static int xapea00x_br_bulk_write(struct xapea00x_device *dev,
> + struct xapea00x_br_bulk_command *header,
> + const void *data, int len)
> +{
> + u8 *buf;
> + unsigned int pipe;
> + int buf_len, actual_len, retval;
> +
> + buf_len = sizeof(struct xapea00x_br_bulk_command) + len;
> + buf = kzalloc(buf_len, GFP_KERNEL);
> + if (!buf) {
> + retval = -ENOMEM;
> + goto out;
> + }
> +
> + memcpy(buf, header, sizeof(struct xapea00x_br_bulk_command));
> + memcpy(buf + sizeof(struct xapea00x_br_bulk_command), data, len);
> +
> + pipe = usb_sndbulkpipe(dev->udev, dev->bulk_out->bEndpointAddress);
> + retval = usb_bulk_msg(dev->udev, pipe, buf, buf_len, &actual_len,
> + XAPEA00X_BR_USB_TIMEOUT);
> + if (retval)
> + goto free_buf;
WTF?
> +free_buf:
> + kzfree(buf);
> +
> +out:
> + return retval;
> +}
> +
[..]
> +static int xapea00x_spi_setup(struct spi_device *spi)
> +{
> + struct xapea00x_device *dev;
> + int retval;
> +
> + dev = spi_master_get_devdata(spi->master);
> +
> + mutex_lock(&dev->usb_mutex);
> + if (!dev->interface) {
> + retval = -ENODEV;
> + goto out;
> + }
> +
> + /* Verify that this is the TPM device */
> + if (spi->chip_select != 0) {
> + retval = -EINVAL;
> + goto err;
> + }
> +
> + /*
> + * Disable auto chip select for the TPM channel.
> + * Must be done after setting the SPI parameters.
> + */
> + retval = xapea00x_br_disable_cs(dev, 0);
> + if (retval)
> + goto err;
> +
> + /* De-assert chip select for the TPM channel. */
> + retval = xapea00x_br_deassert_cs(dev, 0);
> + if (retval)
> + goto err;
> +
> + goto out;
> +
> +err:
> + dev_err(&dev->interface->dev,
> + "configuring SPI channel failed with %d\n", retval);
That could be a simple 'if' statement.
> +
> +out:
> + mutex_unlock(&dev->usb_mutex);
> + return retval;
> +}
> +
>
[..]
> +/**
> + * xapea00x_spi_probe - Register and configure the SPI master.
> + * @dev: the device whose SPI master to register
> + *
> + * Return: If successful, 0. Otherwise a negative error number.
> + */
> +static int xapea00x_spi_probe(struct xapea00x_device *dev)
> +{
> + struct spi_master *spi_master;
> + int retval;
> +
> + spi_master = spi_alloc_master(&dev->interface->dev, sizeof(void *));
> + if (!spi_master) {
> + retval = -ENOMEM;
> + goto err_out;
> + }
> +
> + spi_master_set_devdata(spi_master, dev);
> +
> + spi_master->min_speed_hz = 93 * 1000 + 800; /* 93.9kHz */
> + spi_master->max_speed_hz = 12 * 1000 * 1000; /* 12 MHz */
> +
> + spi_master->bus_num = -1; /* dynamically assigned */
> + spi_master->num_chipselect = 1;
> + spi_master->mode_bits = SPI_MODE_0;
> +
> + spi_master->flags = 0;
> + spi_master->setup = xapea00x_spi_setup;
> + spi_master->transfer_one_message = xapea00x_spi_transfer_one_message;
> +
> + retval = spi_register_master(spi_master);
> +
> + if (retval)
> + goto free_spi;
> +
> + dev->spi_master = spi_master;
Race condition.
> +
> + return 0;
> +
> +free_spi:
> + spi_master_put(spi_master);
> + dev->spi_master = NULL;
> +
> +err_out:
> + return retval;
> +}
> +
> +struct xapea00x_async_probe {
> + struct work_struct work;
> + struct xapea00x_device *dev;
> +};
> +
> +#define work_to_probe(w) container_of(w, struct xapea00x_async_probe, work)
> +
> +/**
> + * xapea00x_init_async_probe - initialize an async probe with the
> + * specified values.
> + * @probe: pointer to the async_probe to initialize
> + * @dev: pointer to the device to probe
> + * @f: pointer to the probe function
> + */
> +static void xapea00x_init_async_probe(struct xapea00x_async_probe *probe,
> + struct xapea00x_device *dev,
> + void (*f)(struct work_struct *work))
> +{
> + INIT_WORK(&probe->work, f);
> + probe->dev = dev;
> +
> + kref_get(&dev->kref);
> + spi_master_get(dev->spi_master);
> +}
> +
> +/**
> + * xapea00x_cleanup_async_probe - clean up the internals of the async
> + * probe. Call this method after the probe has completed.
> + *
> + * The caller is responsible for freeing the probe itself, if
> + * dynamically allocated.
> + *
> + * @probe: pointer to the async_probe to clean up
> + */
> +static void xapea00x_cleanup_async_probe(struct xapea00x_async_probe *probe)
> +{
> + spi_master_put(probe->dev->spi_master);
> + kref_put(&probe->dev->kref, xapea00x_delete);
> +}
> +
> +static struct spi_board_info tpm_board_info = {
> + .modalias = XAPEA00X_TPM_MODALIAS,
> + .max_speed_hz = 43 * 1000 * 1000, // Hz
Are you hardcoding HZ ?
> + .chip_select = 0,
> + .mode = SPI_MODE_0
> +};
Regards
Oliver
---
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2018-05-07 10:05 UTC|newest]
Thread overview: 69+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20180430125418.31344-1-david.bild@xaptum.com>
2018-05-04 13:00 ` [PATCH v3 0/2] Add driver for Xaptum ENF Access card (XAP-EA-00x) David R. Bild
2018-05-04 13:00 ` [PATCH v3 1/2] usb: misc: xapea00x: add driver for Xaptum ENF Access Card David R. Bild
2018-05-04 13:00 ` [v3,1/2] " David R. Bild
2018-05-07 9:58 ` Oliver Neukum [this message]
2018-05-07 9:58 ` Oliver Neukum
2018-05-07 13:31 ` [PATCH v3 1/2] " David R. Bild
2018-05-07 13:31 ` [v3,1/2] " David R. Bild
2018-05-08 9:09 ` [PATCH v3 1/2] " Oliver Neukum
2018-05-08 9:09 ` [v3,1/2] " Oliver Neukum
2018-05-04 13:00 ` [PATCH v3 2/2] usb: misc: xapea00x: perform platform initialization of TPM David R. Bild
2018-05-04 13:00 ` [v3,2/2] " David R. Bild
2018-05-04 19:06 ` [PATCH v3 2/2] " Jason Gunthorpe
2018-05-04 19:06 ` [v3,2/2] " Jason Gunthorpe
2018-05-04 19:56 ` [PATCH v3 2/2] " David R. Bild
2018-05-04 19:56 ` [v3,2/2] " David R. Bild
2018-05-04 20:19 ` [PATCH v3 2/2] " David R. Bild
2018-05-04 20:19 ` [v3,2/2] " David R. Bild
2018-05-06 15:02 ` [PATCH v3 2/2] " Jason Gunthorpe
2018-05-06 15:02 ` [v3,2/2] " Jason Gunthorpe
2018-05-10 1:42 ` [PATCH v3 2/2] " Jarkko Sakkinen
2018-05-10 1:42 ` [v3,2/2] " Jarkko Sakkinen
2018-05-08 10:55 ` [PATCH v3 2/2] " Jarkko Sakkinen
2018-05-08 10:55 ` [v3,2/2] " Jarkko Sakkinen
2018-05-08 15:25 ` [PATCH v3 2/2] " James Bottomley
2018-05-08 15:25 ` [v3,2/2] " James Bottomley
2018-05-08 15:29 ` [PATCH v3 2/2] " David R. Bild
2018-05-08 15:29 ` [v3,2/2] " David R. Bild
2018-05-08 15:36 ` [PATCH v3 2/2] " James Bottomley
2018-05-08 15:36 ` [v3,2/2] " James Bottomley
2018-05-10 1:59 ` [PATCH v3 2/2] " Jarkko Sakkinen
2018-05-10 1:59 ` [v3,2/2] " Jarkko Sakkinen
2018-05-10 14:31 ` [PATCH v3 2/2] " David R. Bild
2018-05-10 14:31 ` [v3,2/2] " David R. Bild
2018-05-13 8:51 ` [PATCH v3 2/2] " Jarkko Sakkinen
2018-05-13 8:51 ` [v3,2/2] " Jarkko Sakkinen
2018-05-25 20:31 ` [PATCH v3 2/2] " Ken Goldman
2018-05-25 20:31 ` [v3,2/2] " Ken Goldman
2018-05-10 14:25 ` [PATCH v3 2/2] " David R. Bild
2018-05-10 14:25 ` [v3,2/2] " David R. Bild
2018-05-10 14:47 ` [PATCH v3 2/2] " James Bottomley
2018-05-10 14:47 ` [v3,2/2] " James Bottomley
2018-05-10 15:17 ` [PATCH v3 2/2] " David R. Bild
2018-05-10 15:17 ` [v3,2/2] " David R. Bild
2018-05-25 20:23 ` [PATCH v3 2/2] " Ken Goldman
2018-05-25 20:23 ` [v3,2/2] " Ken Goldman
2018-05-10 1:44 ` [PATCH v3 2/2] " Jarkko Sakkinen
2018-05-10 1:44 ` [v3,2/2] " Jarkko Sakkinen
2018-05-10 14:29 ` [PATCH v3 2/2] " David R. Bild
2018-05-10 14:29 ` [v3,2/2] " David R. Bild
2018-05-10 1:42 ` [PATCH v3 2/2] " Jarkko Sakkinen
2018-05-10 1:42 ` [v3,2/2] " Jarkko Sakkinen
2018-05-10 14:41 ` [PATCH v3 2/2] " David R. Bild
2018-05-10 14:41 ` [v3,2/2] " David R. Bild
2018-05-13 8:46 ` [PATCH v3 2/2] " Jarkko Sakkinen
2018-05-13 8:46 ` [v3,2/2] " Jarkko Sakkinen
2018-05-14 19:31 ` [PATCH v3 2/2] " Jason Gunthorpe
2018-05-14 19:31 ` [v3,2/2] " Jason Gunthorpe
2018-05-14 19:59 ` [PATCH v3 2/2] " David R. Bild
2018-05-14 19:59 ` [v3,2/2] " David R. Bild
2018-05-14 20:08 ` [PATCH v3 2/2] " Jason Gunthorpe
2018-05-14 20:08 ` [v3,2/2] " Jason Gunthorpe
2018-05-14 20:12 ` [PATCH v3 2/2] " David R. Bild
2018-05-14 20:12 ` [v3,2/2] " David R. Bild
2018-05-07 14:12 ` EXTERNAL: [PATCH v3 2/2] " Jeremy Boone
2018-05-07 14:12 ` Jeremy Boone
2018-05-08 10:47 ` Jarkko Sakkinen
2018-05-08 10:47 ` [v3,2/2] " Jarkko Sakkinen
2018-05-10 14:09 ` [PATCH v3 2/2] " David R. Bild
2018-05-10 14:09 ` [v3,2/2] " David R. Bild
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=1525687128.24345.3.camel@suse.com \
--to=oneukum@suse.com \
--cc=david.bild@xaptum.com \
--cc=gregkh@linuxfoundation.org \
--cc=jarkko.sakkinen@linux.intel.com \
--cc=linux-integrity@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=peterhuewe@gmx.de \
/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.