On Fri, Jul 03 2015, Krzysztof Opasiak wrote:
> I'm looking on this code today an I see another option. We could simply 
> remove nluns from opts and always iterate:
>
> for (i = 0; i < ARRAY_SIZE(luns); ++i)
>       if (luns[i]) {
>               /* Do something useful */
>       }
>
> and add some simple function:
>
> int _fsg_common_get_max_lun(luns)
> {
>       int i;
>
>       for (i = ARRAY_SIZE(luns) - 1; i >= 0 && !luns[i]; --i)
>
>       return i;
> }
>
> with such approach we doesn't need to store number of elements in arrays 
> or max index. Instead of this we just do something only for elements 
> which has been allocated and determine max lun dynamically when handling 
> GET_MAX_LUN request. What do you thing about this Michal? Maybe you have 
> another idea how to solve this?

I think this is reasonable.  One thing to check is how this would affect
changing LUNs.  IIRC we currently do something along the lines of:

  if (lun >= nluns)
    reject
  curlun = luns[lun];  // may be NULL if gadget has non-contiguous LUNs

if we drop nluns we would have just:

  curlun = luns[lun];  // may be NULL if gadget has non-contiguous LUNs

and perhaps then we need:

  if (!curlun)
    reject

But yes, the idea sounds good to me.

-- 
Best regards,                                         _     _
.o. | Liege of Serenely Enlightened Majesty of      o' \,=./ `o
..o | Computer Science,  Michał “mina86” Nazarewicz    (o o)
ooo +--<m...@google.com>--<xmpp:min...@jabber.org>--ooO--(_)--Ooo--
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to