usb: gadget: f_mass_storage: add a level of indirection for luns storage
authorAndrzej Pietrasiewicz <andrzej.p@samsung.com>
Thu, 26 Sep 2013 12:38:18 +0000 (14:38 +0200)
committerMarek Szyprowski <m.szyprowski@samsung.com>
Thu, 15 May 2014 05:26:24 +0000 (07:26 +0200)
commit81d49179bc9e4e5756277f5f40b5a51195e97550
treebb731580ec4a3274b7e819fe894b31c6fa74070c
parentf23e8938568f882e3fa619f275b4003130b1d3bb
usb: gadget: f_mass_storage: add a level of indirection for luns storage

This is needed to prepare for configfs integration.

So far the luns have been allocated during gadget's initialization, based
on the nluns module parameter's value; the exact number is known when the
gadget is initialized and that number of luns is allocated in one go; they
all will be used.

When configfs is in place, the luns will be created one-by-one by the user.
Once the user is satisfied with the number of luns, they activate the
gadget. The number of luns must be <= FSG_MAX_LUN (currently 8), but other
than that it is not known up front and the user need not use contiguous
numbering (apart from the default lun #0). On the other hand, the function
code uses lun numbers to identify them and the number needs to be used
as an index into an array.

Given the above, an array needs to be allocated, but it might happen that
7 out of its 8 elements will not be used. On my machine
sizeof(struct fsg_lun) == 462, so > 3k of memory is allocated but not used
in the worst case.

By adding another level of indirection (allocating an array of pointers
to struct fsg_lun and then allocating individual luns instead of an array
of struct fsg_luns) at most 7 pointers are wasted, which is much less.

This patch also changes some for/while loops to cope with the fact
that in the luns array some entries are potentially empty.

Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
drivers/usb/gadget/f_mass_storage.c