From 896ff3dd7b4d7f69b5c049ce78ed93cf6061f8bd Mon Sep 17 00:00:00 2001 From: Yonghua Yan Date: Tue, 19 Jul 2022 12:33:22 +0800 Subject: [PATCH] usbnet: notify if config to sync with userspace Notify usbnet if configure to sync with netconfig in userspace in factory mode. Clear the gadget in context in case it has been removed when phone switch to host mode. In that case, there will be kernel panic for invalid gadget device access. Change-Id: I28fdb1455eff5fa0592f024e7f1096cbf662de23 Signed-off-by: Yonghua Yan Reviewed-on: https://gerrit.mot.com/2337318 SME-Granted: SME Approvals Granted SLTApproved: Slta Waiver Tested-by: Jira Key Reviewed-by: Haichao Li Reviewed-by: Jianqi Yang Submit-Approved: Jira Key --- drivers/moto_f_usbnet/f_usbnet.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/drivers/moto_f_usbnet/f_usbnet.c b/drivers/moto_f_usbnet/f_usbnet.c index cca9cced18c2..81fdcc30321b 100644 --- a/drivers/moto_f_usbnet/f_usbnet.c +++ b/drivers/moto_f_usbnet/f_usbnet.c @@ -298,12 +298,32 @@ static ssize_t usbnet_iff_flag_show(struct device *dev, }; static DEVICE_ATTR(iff_flag, S_IRUGO, usbnet_iff_flag_show, NULL); +static void usbnet_if_config_notify(struct usbnet_context *context) +{ + struct kobj_uevent_env *env; + struct net_device *net_dev = context->dev; + + env = kzalloc(sizeof(*env), GFP_KERNEL); + if (!env) { + USBNETDBG(context, "%s: alloc uevent error\n", __func__); + return; + } + + add_uevent_var(env, "USBNET_IF_CFG_IP_ADDR=0x%08x", + context->ip_addr); + add_uevent_var(env, "USBNET_IP_CFG_ROUTER_ADDR=0x%08x", + context->router_ip); + add_uevent_var(env, "USBNET_IP_CFG_SUBNET_MASK=0x%08x", + context->subnet_mask); + kobject_uevent_env(&net_dev->dev.kobj, KOBJ_CHANGE, env->envp); + kfree(env); +} + static inline struct usbnet_device *usbnet_func_to_dev(struct usb_function *f) { return container_of(f, struct usbnet_device, function); } - static int ether_queue_out(struct usb_request *req , struct usbnet_context *context) { @@ -523,6 +543,7 @@ static void usbnet_if_config(struct work_struct *work) usbnet_add_files(context); else usbnet_remove_files(context); + usbnet_if_config_notify(context); } static const struct net_device_ops usbnet_eth_netdev_ops = { @@ -589,6 +610,7 @@ static void usbnet_unbind(struct usb_configuration *c, struct usb_function *f) } } + context->gadget = NULL; context->bulk_in = NULL; context->bulk_out = NULL; context->config = 0;