Re: [PATCH V5 net-next 2/3] net: huawei_cdc_ncm: Introduce thehuawei_cdc_ncm driver

From: Oliver Neukum
Date: Mon Sep 30 2013 - 05:08:07 EST


On Mon, 2013-09-30 at 04:50 +0000, Enrico Mioso wrote:

> +static int huawei_cdc_ncm_manage_power(struct usbnet *usbnet_dev, int on)
> +{
> + struct huawei_cdc_ncm_state *drvstate = (void *)&usbnet_dev->data;
> + int rv = 0;
> +
> + if ((on && atomic_add_return(1, &drvstate->pmcount) == 1) ||
> + (!on && atomic_dec_and_test(&drvstate->pmcount))) {
> + rv = usb_autopm_get_interface(usbnet_dev->intf);
> + if (rv < 0)
> + goto err;

The error case corrupts drvstate->pmcount

> + usbnet_dev->intf->needs_remote_wakeup = on;
> + usb_autopm_put_interface(usbnet_dev->intf);
> + }
> +err:
> + return rv;
> +}


> +static int huawei_cdc_ncm_suspend(struct usb_interface *intf, pm_message_t message)
> +{
> + int ret = 0;
> + struct usbnet *usbnet_dev = usb_get_intfdata(intf);
> + struct huawei_cdc_ncm_state *drvstate = (void *)&usbnet_dev->data;
> + struct cdc_ncm_ctx *ctx = drvstate->ctx;
> +
> + if (ctx == NULL) {
> + ret = -1;

That is not a valid way to indicate an error.

> + goto error;
> + }
> +
> + ret = usbnet_suspend(intf, message);
> + if (ret < 0)
> + goto error;
> +
> + if (intf == ctx->control &&
> + drvstate->subdriver &&
> + drvstate->subdriver->suspend)
> + ret = drvstate->subdriver->suspend(intf, message);
> + if (ret < 0)
> + usbnet_resume(intf);
> +
> +error:
> + return ret;
> +}
> +
> +static int huawei_cdc_ncm_resume(struct usb_interface *intf)
> +{
> + int ret = 0;
> + struct usbnet *usbnet_dev = usb_get_intfdata(intf);
> + struct huawei_cdc_ncm_state *drvstate = (void *)&usbnet_dev->data;
> + bool callsub;
> + struct cdc_ncm_ctx *ctx = drvstate->ctx;
> +
> + /* should we call subdriver's resume function? */
> + callsub =
> + (intf == ctx->control &&
> + drvstate->subdriver &&
> + drvstate->subdriver->resume);
> +
> + if (callsub)
> + ret = drvstate->subdriver->resume(intf);
> + if (ret < 0)
> + goto err;
> + ret = usbnet_resume(intf);
> + if (ret < 0 && callsub && drvstate->subdriver->suspend)

You really want drivers with a resume() but no suspend() method?

> + drvstate->subdriver->suspend(intf, PMSG_SUSPEND);
> +err:
> + return ret;
> +}

Regards
Oliver


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