From 167a799c6e88b700c386a010ba3c77ebdbd21a8e Mon Sep 17 00:00:00 2001 From: Linyu Yuan Date: Thu, 18 Nov 2021 12:53:30 +0800 Subject: [PATCH] usb: gadget: configfs: simplify os_desc_item_to_gadget_info() helper since os_desc_group is already a member of struct gadget_info, we can simply just use container_of() to retrieve the latter, without needing to dereference the cg_item's parent pointer. use os_desc_item_to_gadget_info() helper in os_desc (un)link function. Reviewed-by: Jack Pham Signed-off-by: Linyu Yuan Link: https://lore.kernel.org/r/1637211213-16400-2-git-send-email-quic_linyyuan@quicinc.com Signed-off-by: Greg Kroah-Hartman --- drivers/usb/gadget/configfs.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/drivers/usb/gadget/configfs.c b/drivers/usb/gadget/configfs.c index 36c611d1d8d0..ac35fea0452d 100644 --- a/drivers/usb/gadget/configfs.c +++ b/drivers/usb/gadget/configfs.c @@ -791,7 +791,8 @@ static inline struct os_desc *to_os_desc(struct config_item *item) static inline struct gadget_info *os_desc_item_to_gadget_info( struct config_item *item) { - return to_gadget_info(to_os_desc(item)->group.cg_item.ci_parent); + return container_of(to_config_group(item), + struct gadget_info, os_desc_group); } static ssize_t os_desc_use_show(struct config_item *item, char *page) @@ -895,8 +896,7 @@ static void os_desc_attr_release(struct config_item *item) static int os_desc_link(struct config_item *os_desc_ci, struct config_item *usb_cfg_ci) { - struct gadget_info *gi = container_of(to_config_group(os_desc_ci), - struct gadget_info, os_desc_group); + struct gadget_info *gi = os_desc_item_to_gadget_info(os_desc_ci); struct usb_composite_dev *cdev = &gi->cdev; struct config_usb_cfg *c_target = container_of(to_config_group(usb_cfg_ci), @@ -930,8 +930,7 @@ out: static void os_desc_unlink(struct config_item *os_desc_ci, struct config_item *usb_cfg_ci) { - struct gadget_info *gi = container_of(to_config_group(os_desc_ci), - struct gadget_info, os_desc_group); + struct gadget_info *gi = os_desc_item_to_gadget_info(os_desc_ci); struct usb_composite_dev *cdev = &gi->cdev; mutex_lock(&gi->lock);