Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1651905

Re: [PATCH v2 13/27] thunderbolt: Read vendor and device name from DROM

From Andy Shevchenko <andy.shevchenko@gmail.com>
Newsgroups linux.kernel
Subject Re: [PATCH v2 13/27] thunderbolt: Read vendor and device name from DROM
Date 2017-05-27 18:00 +0200
Message-ID <tLMid-5VB-3@gated-at.bofh.it> (permalink)
References <tLq81-87A-5@gated-at.bofh.it> <tLq82-87A-43@gated-at.bofh.it> <tLMid-5VB-5@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Sat, May 27, 2017 at 6:57 PM, Andy Shevchenko
<andy.shevchenko@gmail.com> wrote:
> On Fri, May 26, 2017 at 7:09 PM, Mika Westerberg
> <mika.westerberg@linux.intel.com> wrote:
>> The device DROM contains name of the vendor and device among other
>> things. Extract this information and expose it to the userspace via two
>> new attributes.
>
>> +static const char *parse_name(const u8 *data, u8 len)
>
> Hmm... (name)
>
>> +{
>> +       char *name;
>> +
>> +       name = kmemdup(data, len, GFP_KERNEL);
>
> Since it's ASCII by specification it may make sense to use
>
> sw->..._name = kstrndup(entry->data, sizeof(*header), GFP_KERNEL);

sizeof(*header) - 1, of course.

> if (!sw->..._name)
>  return -ENOMEM;
>
> just in place, instead of this entire function.
>
>> +       if (name)
>> +               name[len - 1] = '\0';
>> +       return name;
>> +}
>> +
>> +static int tb_drom_parse_entry_generic(struct tb_switch *sw,
>> +               struct tb_drom_entry_header *header)
>> +{
>> +       const struct tb_drom_entry_generic *entry =
>> +               (const struct tb_drom_entry_generic *)header;
>> +
>> +       switch (header->index) {
>> +       case 1:
>> +               /* Length includes 2 bytes header so remove it before copy */
>> +               sw->vendor_name = parse_name(entry->data,
>> +                                            header->len - sizeof(*header));
>> +               if (!sw->vendor_name)
>> +                       return -ENOMEM;
>> +               break;
>> +
>> +       case 2:
>> +               sw->device_name = parse_name(entry->data,
>> +                                            header->len - sizeof(*header));
>> +               if (!sw->device_name)
>> +                       return -ENOMEM;
>> +               break;
>> +       }
>> +
>> +       return 0;
>> +}
>
> --
> With Best Regards,
> Andy Shevchenko



-- 
With Best Regards,
Andy Shevchenko

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH v2 13/27] thunderbolt: Read vendor and device name from DROM Mika Westerberg <mika.westerberg@linux.intel.com> - 2017-05-26 18:20 +0200
  Re: [PATCH v2 13/27] thunderbolt: Read vendor and device name from DROM Andy Shevchenko <andy.shevchenko@gmail.com> - 2017-05-27 18:00 +0200
  Re: [PATCH v2 13/27] thunderbolt: Read vendor and device name from DROM Andy Shevchenko <andy.shevchenko@gmail.com> - 2017-05-27 18:00 +0200
    Re: [PATCH v2 13/27] thunderbolt: Read vendor and device name from  DROM Mika Westerberg <mika.westerberg@linux.intel.com> - 2017-05-28 10:50 +0200

csiph-web