RE: [PATCH] iio_trigger_find_by_name: Skip trailing newline if available

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

 



Jonathan Cameron wrote on 2010-03-22:
> On 03/08/10 09:31, Hennerich, Michael wrote:
>> Skip trailing newline if available.
>>
>> From: Michael Hennerich <Michael.Hennerich@xxxxxxxxxx>
>
> Dear Michael,
>
> Just found this one whilst trying to sort out a clean iio tree.
> (sorry I completely failed to reply originally)
>
> Anyhow, I agree with the principal that we should be ignoring the
> newline.  Actually we should be ignoring whitespace before and after
> the string we are actually after.

Well - in most cases people use #echo so there shouldn't be a problem with white space before and after.
However the newline is going to bug in case you don't use #echo -n.
I've seen many sysfs_set functions also stripping the '\n' from the string.

> Perhaps a cleaner approach is to
> use sscanf to pull out the string alone?

sscanf() is certainly a alternative here.

> I don't think we need to
> allow for whitespace in the trigger name (though obviously it should
> be documented if we do not).  Technically I believe (via the
> convenient lwn article last week on the topic) we should ignore white
> space but return -EINVAL if there is say one word, some white space
> and then another word...  Not sure if there is a particularly clean
> way to do that however.
>
> What do you think?

I agree - Don't allow whitespace in the trigger name.

Michael

>
> Jonathan
>>
>> Index: drivers/staging/iio/industrialio-trigger.c
>> ===================================================================
>> --- drivers/staging/iio/industrialio-trigger.c  (revision 8368)
>> +++ drivers/staging/iio/industrialio-trigger.c  (working copy)
>> @@ -155,6 +155,9 @@
>>         struct iio_trigger *trig;
>>         bool found = false;
>> +       if (len && name[len - 1] == '\n')
>> +               len--;
>> +
>>         mutex_lock(&iio_trigger_list_lock);
>>         list_for_each_entry(trig, &iio_trigger_list, list) {
>>                 if (strncmp(trig->name, name, len) == 0) {
>> ------------------------------------------------------------------
>> ********* Analog Devices GmbH              Open Platform Solutions
>> **  *****
>> **     ** Wilhelm-Wagenfeld-Strasse 6
>> **  ***** D-80807 Munich
>> ********* Germany
>> Registergericht München HRB 40368,  Geschäftsführer: Thomas Wessel,
>> William A. Martin, Margaret K. Seif
>>
>>
>>
Greetings,
Michael

Analog Devices GmbH      Wilhelm-Wagenfeld-Str. 6      80807 Muenchen
Sitz der Gesellschaft Muenchen, Registergericht Muenchen HRB 4036 Geschaeftsfuehrer Thomas Wessel, William A. Martin, Margaret Seif


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

[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Input]     [Linux Kernel]     [Linux SCSI]     [X.org]

  Powered by Linux