[PATCH 1/3] usb: gadget: rndis: use rndis_params instead of configNr

2015-03-20 Thread Andrzej Pietrasiewicz
RNDIS function has a limitation on the number of allowed instances.
So far it has been RNDIS_MAX_CONFIGS, which happens to be one.
In order to eliminate this kind of arbitrary limitation we should not
preallocate a predefined (RNDIS_MAX_CONFIGS) array of struct rndis_params
instances but instead allow allocating them on demand.

This patch prepares the elimination of the said limit by converting all the
functions which accept rndis config number to accept a pointer to the
actual struct rndis_params. Consequently, rndis_register() returns
a pointer to a corresponding struct rndis_params instance. The pointer
is then always used by f_rndis.c instead of config number when it talks
to rndis.c API.

A nice side-effect of the changes is that many lines of code in rndis.c
become shorter and fit in 80 columns.

If a function prototype changes in rndis.h a style cleanup is made
at the same time, otherwise checkpatch complains that the patch
has style problems.

Signed-off-by: Andrzej Pietrasiewicz 
---
@Felipe:

For some reason the original version was missing an opening "("
at the prototype of rndis_free_response() in rndis.h.
Now it should be fine.

 drivers/usb/gadget/function/f_rndis.c |  38 +++---
 drivers/usb/gadget/function/rndis.c   | 213 +++---
 drivers/usb/gadget/function/rndis.h   |  29 ++---
 3 files changed, 129 insertions(+), 151 deletions(-)

diff --git a/drivers/usb/gadget/function/f_rndis.c 
b/drivers/usb/gadget/function/f_rndis.c
index 829edf8..2dafe72 100644
--- a/drivers/usb/gadget/function/f_rndis.c
+++ b/drivers/usb/gadget/function/f_rndis.c
@@ -76,7 +76,7 @@ struct f_rndis {
u8  ethaddr[ETH_ALEN];
u32 vendorID;
const char  *manufacturer;
-   int config;
+   struct rndis_params *params;
 
struct usb_ep   *notify;
struct usb_request  *notify_req;
@@ -453,7 +453,7 @@ static void rndis_command_complete(struct usb_ep *ep, 
struct usb_request *req)
 
/* received RNDIS command from USB_CDC_SEND_ENCAPSULATED_COMMAND */
 // spin_lock(&dev->lock);
-   status = rndis_msg_parser(rndis->config, (u8 *) req->buf);
+   status = rndis_msg_parser(rndis->params, (u8 *) req->buf);
if (status < 0)
pr_err("RNDIS command error %d, %d/%d\n",
status, req->actual, req->length);
@@ -499,12 +499,12 @@ rndis_setup(struct usb_function *f, const struct 
usb_ctrlrequest *ctrl)
u32 n;
 
/* return the result */
-   buf = rndis_get_next_response(rndis->config, &n);
+   buf = rndis_get_next_response(rndis->params, &n);
if (buf) {
memcpy(req->buf, buf, n);
req->complete = rndis_response_complete;
req->context = rndis;
-   rndis_free_response(rndis->config, buf);
+   rndis_free_response(rndis->params, buf);
value = n;
}
/* else stalls ... spec says to avoid that */
@@ -597,7 +597,7 @@ static int rndis_set_alt(struct usb_function *f, unsigned 
intf, unsigned alt)
if (IS_ERR(net))
return PTR_ERR(net);
 
-   rndis_set_param_dev(rndis->config, net,
+   rndis_set_param_dev(rndis->params, net,
&rndis->port.cdc_filter);
} else
goto fail;
@@ -617,7 +617,7 @@ static void rndis_disable(struct usb_function *f)
 
DBG(cdev, "rndis deactivated\n");
 
-   rndis_uninit(rndis->config);
+   rndis_uninit(rndis->params);
gether_disconnect(&rndis->port);
 
usb_ep_disable(rndis->notify);
@@ -640,9 +640,9 @@ static void rndis_open(struct gether *geth)
 
DBG(cdev, "%s\n", __func__);
 
-   rndis_set_param_medium(rndis->config, RNDIS_MEDIUM_802_3,
+   rndis_set_param_medium(rndis->params, RNDIS_MEDIUM_802_3,
bitrate(cdev->gadget) / 100);
-   rndis_signal_connect(rndis->config);
+   rndis_signal_connect(rndis->params);
 }
 
 static void rndis_close(struct gether *geth)
@@ -651,8 +651,8 @@ static void rndis_close(struct gether *geth)
 
DBG(geth->func.config->cdev, "%s\n", __func__);
 
-   rndis_set_param_medium(rndis->config, RNDIS_MEDIUM_802_3, 0);
-   rndis_signal_disconnect(rndis->config);
+   rndis_set_param_medium(rndis->params, RNDIS_MEDIUM_802_3, 0);
+   rndis_signal_disconnect(rndis->params);
 }
 
 /*-*/
@@ -796,11 +796,11 @@ rndis_bind(struct usb_configuration *c, struct 
usb_function *f)
rndis->port.open = rndis_open;
   

[PATCH 1/3] usb: gadget: rndis: use rndis_params instead of configNr

2015-02-06 Thread Andrzej Pietrasiewicz
RNDIS function has a limitation on the number of allowed instances.
So far it has been RNDIS_MAX_CONFIGS, which happens to be one.
In order to eliminate this kind of arbitrary limitation we should not
preallocate a predefined (RNDIS_MAX_CONFIGS) array of struct rndis_params
instances but instead allow allocating them on demand.

This patch prepares the elimination of the said limit by converting all the
functions which accept rndis config number to accept a pointer to the
actual struct rndis_params. Consequently, rndis_register() returns
a pointer to a corresponding struct rndis_params instance. The pointer
is then always used by f_rndis.c instead of config number when it talks
to rndis.c API.

A nice side-effect of the changes is that many lines of code in rndis.c
become shorter and fit in 80 columns.

If a function prototype changes in rndis.h a style cleanup is made
at the same time, otherwise checkpatch complains that the patch
has style problems.

Signed-off-by: Andrzej Pietrasiewicz 
---
 drivers/usb/gadget/function/f_rndis.c |  38 +++---
 drivers/usb/gadget/function/rndis.c   | 213 +++---
 drivers/usb/gadget/function/rndis.h   |  29 ++---
 3 files changed, 129 insertions(+), 151 deletions(-)

diff --git a/drivers/usb/gadget/function/f_rndis.c 
b/drivers/usb/gadget/function/f_rndis.c
index 829edf8..2dafe72 100644
--- a/drivers/usb/gadget/function/f_rndis.c
+++ b/drivers/usb/gadget/function/f_rndis.c
@@ -76,7 +76,7 @@ struct f_rndis {
u8  ethaddr[ETH_ALEN];
u32 vendorID;
const char  *manufacturer;
-   int config;
+   struct rndis_params *params;
 
struct usb_ep   *notify;
struct usb_request  *notify_req;
@@ -453,7 +453,7 @@ static void rndis_command_complete(struct usb_ep *ep, 
struct usb_request *req)
 
/* received RNDIS command from USB_CDC_SEND_ENCAPSULATED_COMMAND */
 // spin_lock(&dev->lock);
-   status = rndis_msg_parser(rndis->config, (u8 *) req->buf);
+   status = rndis_msg_parser(rndis->params, (u8 *) req->buf);
if (status < 0)
pr_err("RNDIS command error %d, %d/%d\n",
status, req->actual, req->length);
@@ -499,12 +499,12 @@ rndis_setup(struct usb_function *f, const struct 
usb_ctrlrequest *ctrl)
u32 n;
 
/* return the result */
-   buf = rndis_get_next_response(rndis->config, &n);
+   buf = rndis_get_next_response(rndis->params, &n);
if (buf) {
memcpy(req->buf, buf, n);
req->complete = rndis_response_complete;
req->context = rndis;
-   rndis_free_response(rndis->config, buf);
+   rndis_free_response(rndis->params, buf);
value = n;
}
/* else stalls ... spec says to avoid that */
@@ -597,7 +597,7 @@ static int rndis_set_alt(struct usb_function *f, unsigned 
intf, unsigned alt)
if (IS_ERR(net))
return PTR_ERR(net);
 
-   rndis_set_param_dev(rndis->config, net,
+   rndis_set_param_dev(rndis->params, net,
&rndis->port.cdc_filter);
} else
goto fail;
@@ -617,7 +617,7 @@ static void rndis_disable(struct usb_function *f)
 
DBG(cdev, "rndis deactivated\n");
 
-   rndis_uninit(rndis->config);
+   rndis_uninit(rndis->params);
gether_disconnect(&rndis->port);
 
usb_ep_disable(rndis->notify);
@@ -640,9 +640,9 @@ static void rndis_open(struct gether *geth)
 
DBG(cdev, "%s\n", __func__);
 
-   rndis_set_param_medium(rndis->config, RNDIS_MEDIUM_802_3,
+   rndis_set_param_medium(rndis->params, RNDIS_MEDIUM_802_3,
bitrate(cdev->gadget) / 100);
-   rndis_signal_connect(rndis->config);
+   rndis_signal_connect(rndis->params);
 }
 
 static void rndis_close(struct gether *geth)
@@ -651,8 +651,8 @@ static void rndis_close(struct gether *geth)
 
DBG(geth->func.config->cdev, "%s\n", __func__);
 
-   rndis_set_param_medium(rndis->config, RNDIS_MEDIUM_802_3, 0);
-   rndis_signal_disconnect(rndis->config);
+   rndis_set_param_medium(rndis->params, RNDIS_MEDIUM_802_3, 0);
+   rndis_signal_disconnect(rndis->params);
 }
 
 /*-*/
@@ -796,11 +796,11 @@ rndis_bind(struct usb_configuration *c, struct 
usb_function *f)
rndis->port.open = rndis_open;
rndis->port.close = rndis_close;
 
-   rndis_set_param_medium(rndis->config, RNDIS_MEDIUM_802_3, 0);
-   rndis_set_host_mac(rndis->config, 

Re: [PATCH 1/3] usb: gadget: rndis: use rndis_params instead of configNr

2015-03-19 Thread Felipe Balbi
On Fri, Feb 06, 2015 at 01:43:28PM +0100, Andrzej Pietrasiewicz wrote:
> RNDIS function has a limitation on the number of allowed instances.
> So far it has been RNDIS_MAX_CONFIGS, which happens to be one.
> In order to eliminate this kind of arbitrary limitation we should not
> preallocate a predefined (RNDIS_MAX_CONFIGS) array of struct rndis_params
> instances but instead allow allocating them on demand.
> 
> This patch prepares the elimination of the said limit by converting all the
> functions which accept rndis config number to accept a pointer to the
> actual struct rndis_params. Consequently, rndis_register() returns
> a pointer to a corresponding struct rndis_params instance. The pointer
> is then always used by f_rndis.c instead of config number when it talks
> to rndis.c API.
> 
> A nice side-effect of the changes is that many lines of code in rndis.c
> become shorter and fit in 80 columns.
> 
> If a function prototype changes in rndis.h a style cleanup is made
> at the same time, otherwise checkpatch complains that the patch
> has style problems.
> 
> Signed-off-by: Andrzej Pietrasiewicz 

doesn't build.

./drivers/usb/gadget/function//rndis.h:213:26: error: void declaration
./drivers/usb/gadget/function//rndis.h:213:26: error: Expected ; at end
of declaration
./drivers/usb/gadget/function//rndis.h:213:26: error: got struct
./drivers/usb/gadget/function//rndis.h:213:26: error: void declaration
./drivers/usb/gadget/function//rndis.h:213:26: error: Expected ; at end
of declaration
./drivers/usb/gadget/function//rndis.h:213:26: error: got struct
drivers/usb/gadget/function/rndis.h:213:26: error: void declaration
drivers/usb/gadget/function/rndis.h:213:26: error: Expected ; at end of
declaration
drivers/usb/gadget/function/rndis.h:213:26: error: got struct
drivers/usb/gadget/function/f_rndis.c:507:52: error: not a function
rndis_free_response
drivers/usb/gadget/function/rndis.h:213:26: error: void declaration
drivers/usb/gadget/function/rndis.h:213:26: error: Expected ; at end of
declaration
drivers/usb/gadget/function/rndis.h:213:26: error: got struct
drivers/usb/gadget/function/rndis.c:764:36: error: not a function
rndis_free_response
drivers/usb/gadget/function/rndis.c:944:6: error: symbol
'rndis_free_response' redeclared with different type (originally
declared at drivers/usb/gadget/function/rndis.h:213) - different base
types
./drivers/usb/gadget/function//rndis.h:213:26: error: void declaration
./drivers/usb/gadget/function//rndis.h:213:26: error: Expected ; at end
of declaration
./drivers/usb/gadget/function//rndis.h:213:26: error: got struct
In file included from drivers/usb/gadget/legacy/ether.c:101:0:
./drivers/usb/gadget/function/rndis.h:213:26: error: expected ‘=’, ‘,’,
‘;’, ‘asm’ or ‘__attribute__’ before ‘struct’
 void rndis_free_response struct rndis_params *params, u8 *buf);

-- 
balbi


signature.asc
Description: Digital signature