[PATCH 6/8] typec: mux: Allow multiple mux_devs per mux
Dan Carpenter
dan.carpenter at oracle.com
Thu Jan 6 02:43:32 PST 2022
Hi Bjorn,
url: https://github.com/0day-ci/linux/commits/Bjorn-Andersson/typec-mux-Introduce-support-for-multiple-TypeC-muxes/20211228-132045
base: https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git usb-testing
config: x86_64-randconfig-m001-20211228 (https://download.01.org/0day-ci/archive/20211228/202112282331.V8Kkx4jf-lkp@intel.com/config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp at intel.com>
Reported-by: Dan Carpenter <dan.carpenter at oracle.com>
smatch warnings:
drivers/usb/typec/mux.c:114 fwnode_typec_switch_get() warn: possible memory leak of 'sw'
drivers/usb/typec/mux.c:373 fwnode_typec_mux_get() warn: possible memory leak of 'mux'
vim +/sw +114 drivers/usb/typec/mux.c
d1c6a769cdf466 Heikki Krogerus 2020-03-02 71 struct typec_switch *fwnode_typec_switch_get(struct fwnode_handle *fwnode)
bdecb33af34f79 Heikki Krogerus 2018-03-20 72 {
8ddb6d277ef580 Bjorn Andersson 2021-12-27 73 struct typec_switch_dev *sw_devs[TYPEC_MUX_MAX_DEVS];
bdecb33af34f79 Heikki Krogerus 2018-03-20 74 struct typec_switch *sw;
8ddb6d277ef580 Bjorn Andersson 2021-12-27 75 int count;
8ddb6d277ef580 Bjorn Andersson 2021-12-27 76 int err;
8ddb6d277ef580 Bjorn Andersson 2021-12-27 77 int i;
bdecb33af34f79 Heikki Krogerus 2018-03-20 78
8d7c70bd032dda Bjorn Andersson 2021-12-27 79 sw = kzalloc(sizeof(*sw), GFP_KERNEL);
8d7c70bd032dda Bjorn Andersson 2021-12-27 80 if (!sw)
8d7c70bd032dda Bjorn Andersson 2021-12-27 81 return ERR_PTR(-ENOMEM);
8d7c70bd032dda Bjorn Andersson 2021-12-27 82
8ddb6d277ef580 Bjorn Andersson 2021-12-27 83 count = fwnode_connection_find_matches(fwnode, "orientation-switch", NULL,
8ddb6d277ef580 Bjorn Andersson 2021-12-27 84 typec_switch_match,
8ddb6d277ef580 Bjorn Andersson 2021-12-27 85 (void **)sw_devs,
8ddb6d277ef580 Bjorn Andersson 2021-12-27 86 ARRAY_SIZE(sw_devs));
8ddb6d277ef580 Bjorn Andersson 2021-12-27 87 if (count <= 0) {
8d7c70bd032dda Bjorn Andersson 2021-12-27 88 kfree(sw);
8ddb6d277ef580 Bjorn Andersson 2021-12-27 89 return NULL;
8d7c70bd032dda Bjorn Andersson 2021-12-27 90 }
8d7c70bd032dda Bjorn Andersson 2021-12-27 91
8ddb6d277ef580 Bjorn Andersson 2021-12-27 92 for (i = 0; i < count; i++) {
8ddb6d277ef580 Bjorn Andersson 2021-12-27 93 if (IS_ERR(sw_devs[i])) {
8ddb6d277ef580 Bjorn Andersson 2021-12-27 94 err = PTR_ERR(sw_devs[i]);
8ddb6d277ef580 Bjorn Andersson 2021-12-27 95 goto put_sw_devs;
"sw" not freed on this path.
8ddb6d277ef580 Bjorn Andersson 2021-12-27 96 }
8ddb6d277ef580 Bjorn Andersson 2021-12-27 97 }
8ddb6d277ef580 Bjorn Andersson 2021-12-27 98
8ddb6d277ef580 Bjorn Andersson 2021-12-27 99 for (i = 0; i < count; i++) {
8ddb6d277ef580 Bjorn Andersson 2021-12-27 100 WARN_ON(!try_module_get(sw_devs[i]->dev.parent->driver->owner));
8ddb6d277ef580 Bjorn Andersson 2021-12-27 101 sw->sw_devs[i] = sw_devs[i];
8ddb6d277ef580 Bjorn Andersson 2021-12-27 102 }
8d7c70bd032dda Bjorn Andersson 2021-12-27 103
8ddb6d277ef580 Bjorn Andersson 2021-12-27 104 sw->num_sw_devs = count;
bdecb33af34f79 Heikki Krogerus 2018-03-20 105
bdecb33af34f79 Heikki Krogerus 2018-03-20 106 return sw;
8ddb6d277ef580 Bjorn Andersson 2021-12-27 107
8ddb6d277ef580 Bjorn Andersson 2021-12-27 108 put_sw_devs:
8ddb6d277ef580 Bjorn Andersson 2021-12-27 109 for (i = 0; i < count; i++) {
8ddb6d277ef580 Bjorn Andersson 2021-12-27 110 if (!IS_ERR(sw_devs[i]))
8ddb6d277ef580 Bjorn Andersson 2021-12-27 111 put_device(&sw_devs[i]->dev);
8ddb6d277ef580 Bjorn Andersson 2021-12-27 112 }
8ddb6d277ef580 Bjorn Andersson 2021-12-27 113
8ddb6d277ef580 Bjorn Andersson 2021-12-27 @114 return ERR_PTR(err);
bdecb33af34f79 Heikki Krogerus 2018-03-20 115 }
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
More information about the linux-phy
mailing list