Skip to content

Commit

Permalink
usb: gadget: rndis: use rndis_params instead of configNr
Browse files Browse the repository at this point in the history
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 <andrzej.p@samsung.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
  • Loading branch information
Andrzej Pietrasiewicz authored and Felipe Balbi committed May 7, 2015
1 parent d74c23d commit 83210e5
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 151 deletions.
38 changes: 19 additions & 19 deletions drivers/usb/gadget/function/f_rndis.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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)
Expand All @@ -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);
}

/*-------------------------------------------------------------------------*/
Expand Down Expand Up @@ -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, rndis->ethaddr);
rndis_set_param_medium(rndis->params, RNDIS_MEDIUM_802_3, 0);
rndis_set_host_mac(rndis->params, rndis->ethaddr);

if (rndis->manufacturer && rndis->vendorID &&
rndis_set_param_vendor(rndis->config, rndis->vendorID,
rndis_set_param_vendor(rndis->params, rndis->vendorID,
rndis->manufacturer)) {
status = -EINVAL;
goto fail_free_descs;
Expand Down Expand Up @@ -944,7 +944,7 @@ static void rndis_free(struct usb_function *f)
struct f_rndis_opts *opts;

rndis = func_to_rndis(f);
rndis_deregister(rndis->config);
rndis_deregister(rndis->params);
opts = container_of(f->fi, struct f_rndis_opts, func_inst);
kfree(rndis);
mutex_lock(&opts->lock);
Expand All @@ -968,7 +968,7 @@ static struct usb_function *rndis_alloc(struct usb_function_instance *fi)
{
struct f_rndis *rndis;
struct f_rndis_opts *opts;
int status;
struct rndis_params *params;

/* allocate and initialize one new instance */
rndis = kzalloc(sizeof(*rndis), GFP_KERNEL);
Expand Down Expand Up @@ -1002,12 +1002,12 @@ static struct usb_function *rndis_alloc(struct usb_function_instance *fi)
rndis->port.func.disable = rndis_disable;
rndis->port.func.free_func = rndis_free;

status = rndis_register(rndis_response_available, rndis);
if (status < 0) {
params = rndis_register(rndis_response_available, rndis);
if (IS_ERR(params)) {
kfree(rndis);
return ERR_PTR(status);
return ERR_CAST(params);
}
rndis->config = status;
rndis->params = params;

return &rndis->port.func;
}
Expand Down
Loading

0 comments on commit 83210e5

Please sign in to comment.