Re: [PATCH 1/2] usb: misc: xapea00x: add driver for Xaptum ENF Access Card

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Jan 25, 2018 at 10:34 AM, David R. Bild <david.bild@xxxxxxxxxx> wrote:
> On Thu, Jan 11, 2018 at 4:27 AM, Oliver Neukum <oneukum@xxxxxxxx> wrote:
>>
>> Am Mittwoch, den 10.01.2018, 10:58 -0600 schrieb  David R. Bild :
>
>> > +static void xapea00x_tpm_probe(struct work_struct *work)
>> > +{
>> > +     struct xapea00x_async_probe *probe = work_to_probe(work);
>> > +     struct xapea00x_device *dev = probe->dev;
>> > +     struct spi_master *spi_master = dev->spi_master;
>> > +     struct spi_device *tpm;
>> > +     int retval;
>> > +
>> > +     tpm = spi_new_device(spi_master, &tpm_board_info);
>> > +     mutex_lock(&dev->usb_mutex);
>> > +     if (!dev->interface) {
>> > +             retval = -ENODEV;
>> > +             goto out;
>> > +     }
>> > +     if (!tpm) {
>>
>> Why test this under a mutex?
>>
>
> dev->interface being NULL/non-NULL is used as a flag to determine if
> the USB device has been unregistered.  So, the mutex needs to be held
> when dereferencing dev->interface subsequently.
>
> Performing the test before acquiring the lock would be a race condition.
>

I'm realizing I misunderstood this comment --- you're referring to
testing "!tpm", not testing "!dev->interface".

It's because the in the failure case (!tpm), I want the error message
to include the "dev->interface->dev" identifier.  But that
dereferencing is only safe if "dev->interface" isn't NULL.

>> > +             retval = -ENODEV;
>> > +             dev_err(&dev->interface->dev,
>> > +                     "unable to add spi device for TPM\n");
>> > +             goto err;
>> > +     }
>> > +


Thanks much,
David
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux