[android-common:android14-kiwi-6.1 192/192] drivers/base/power/common.c:226 dev_pm_domain_attach_list() warn: double check that we're allocating correct size: 4 vs 8
kernel test robot <[email protected]> Tue, 21 Jul 2026 15:08:59 +0800
| Newsgroups | dev.linux.lists.oe-kbuild |
|---|---|
| Message-ID | <[email protected]> |
BCC: [email protected] CC: [email protected] TO: [email protected] tree: https://android.googlesource.com/kernel/common android14-kiwi-6.1 head: b3c531e1677cf574dd7ffc9bfce3a298c74ef2f8 commit: b45e2c927411cd2e48dd5eae01165f2fe01ee27e [192/192] UPSTREAM: PM: domains: Fix alloc/free in dev_pm_domain_attach|detach_list() :::::: branch date: 13 hours ago :::::: commit date: 1 year, 2 months ago config: arm-randconfig-r071-20260716 (https://download.01.org/0day-ci/archive/20260721/[email protected]/config) compiler: clang version 24.0.0git (https://github.com/llvm/llvm-project 5c0dfced1adc55429e32b1db08570abd3a219d85) smatch: v0.5.0-9187-g5189e3fb If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <[email protected]> | Reported-by: Dan Carpenter <[email protected]> | Closes: https://lore.kernel.org/r/[email protected]/ smatch warnings: drivers/base/power/common.c:226 dev_pm_domain_attach_list() warn: double check that we're allocating correct size: 4 vs 8 vim +226 drivers/base/power/common.c 27dceb81f445c5 Ulf Hansson 2018-06-29 169 f88293625b3d04 Ulf Hansson 2024-01-26 170 /** f88293625b3d04 Ulf Hansson 2024-01-26 171 * dev_pm_domain_attach_list - Associate a device with its PM domains. f88293625b3d04 Ulf Hansson 2024-01-26 172 * @dev: The device used to lookup the PM domains for. f88293625b3d04 Ulf Hansson 2024-01-26 173 * @data: The data used for attaching to the PM domains. f88293625b3d04 Ulf Hansson 2024-01-26 174 * @list: An out-parameter with an allocated list of attached PM domains. f88293625b3d04 Ulf Hansson 2024-01-26 175 * f88293625b3d04 Ulf Hansson 2024-01-26 176 * This function helps to attach a device to its multiple PM domains. The f88293625b3d04 Ulf Hansson 2024-01-26 177 * caller, which is typically a driver's probe function, may provide a list of f88293625b3d04 Ulf Hansson 2024-01-26 178 * names for the PM domains that we should try to attach the device to, but it f88293625b3d04 Ulf Hansson 2024-01-26 179 * may also provide an empty list, in case the attach should be done for all of f88293625b3d04 Ulf Hansson 2024-01-26 180 * the available PM domains. f88293625b3d04 Ulf Hansson 2024-01-26 181 * f88293625b3d04 Ulf Hansson 2024-01-26 182 * Callers must ensure proper synchronization of this function with power f88293625b3d04 Ulf Hansson 2024-01-26 183 * management callbacks. f88293625b3d04 Ulf Hansson 2024-01-26 184 * f88293625b3d04 Ulf Hansson 2024-01-26 185 * Returns the number of attached PM domains or a negative error code in case of f88293625b3d04 Ulf Hansson 2024-01-26 186 * a failure. Note that, to detach the list of PM domains, the driver shall call f88293625b3d04 Ulf Hansson 2024-01-26 187 * dev_pm_domain_detach_list(), typically during the remove phase. f88293625b3d04 Ulf Hansson 2024-01-26 188 */ f88293625b3d04 Ulf Hansson 2024-01-26 189 int dev_pm_domain_attach_list(struct device *dev, f88293625b3d04 Ulf Hansson 2024-01-26 190 const struct dev_pm_domain_attach_data *data, f88293625b3d04 Ulf Hansson 2024-01-26 191 struct dev_pm_domain_list **list) f88293625b3d04 Ulf Hansson 2024-01-26 192 { f88293625b3d04 Ulf Hansson 2024-01-26 193 struct device_node *np = dev->of_node; f88293625b3d04 Ulf Hansson 2024-01-26 194 struct dev_pm_domain_list *pds; f88293625b3d04 Ulf Hansson 2024-01-26 195 struct device *pd_dev = NULL; f88293625b3d04 Ulf Hansson 2024-01-26 196 int ret, i, num_pds = 0; f88293625b3d04 Ulf Hansson 2024-01-26 197 bool by_id = true; b45e2c927411cd Ulf Hansson 2024-10-02 198 size_t size; f88293625b3d04 Ulf Hansson 2024-01-26 199 u32 pd_flags = data ? data->pd_flags : 0; f88293625b3d04 Ulf Hansson 2024-01-26 200 u32 link_flags = pd_flags & PD_FLAG_NO_DEV_LINK ? 0 : f88293625b3d04 Ulf Hansson 2024-01-26 201 DL_FLAG_STATELESS | DL_FLAG_PM_RUNTIME; f88293625b3d04 Ulf Hansson 2024-01-26 202 f88293625b3d04 Ulf Hansson 2024-01-26 203 if (dev->pm_domain) f88293625b3d04 Ulf Hansson 2024-01-26 204 return -EEXIST; f88293625b3d04 Ulf Hansson 2024-01-26 205 f88293625b3d04 Ulf Hansson 2024-01-26 206 /* For now this is limited to OF based platforms. */ f88293625b3d04 Ulf Hansson 2024-01-26 207 if (!np) f88293625b3d04 Ulf Hansson 2024-01-26 208 return 0; f88293625b3d04 Ulf Hansson 2024-01-26 209 f88293625b3d04 Ulf Hansson 2024-01-26 210 if (data && data->pd_names) { f88293625b3d04 Ulf Hansson 2024-01-26 211 num_pds = data->num_pd_names; f88293625b3d04 Ulf Hansson 2024-01-26 212 by_id = false; f88293625b3d04 Ulf Hansson 2024-01-26 213 } else { f88293625b3d04 Ulf Hansson 2024-01-26 214 num_pds = of_count_phandle_with_args(np, "power-domains", f88293625b3d04 Ulf Hansson 2024-01-26 215 "#power-domain-cells"); f88293625b3d04 Ulf Hansson 2024-01-26 216 } f88293625b3d04 Ulf Hansson 2024-01-26 217 f88293625b3d04 Ulf Hansson 2024-01-26 218 if (num_pds <= 0) f88293625b3d04 Ulf Hansson 2024-01-26 219 return 0; f88293625b3d04 Ulf Hansson 2024-01-26 220 b45e2c927411cd Ulf Hansson 2024-10-02 221 pds = kzalloc(sizeof(*pds), GFP_KERNEL); f88293625b3d04 Ulf Hansson 2024-01-26 222 if (!pds) f88293625b3d04 Ulf Hansson 2024-01-26 223 return -ENOMEM; f88293625b3d04 Ulf Hansson 2024-01-26 224 b45e2c927411cd Ulf Hansson 2024-10-02 225 size = sizeof(*pds->pd_devs) + sizeof(*pds->pd_links); b45e2c927411cd Ulf Hansson 2024-10-02 @226 pds->pd_devs = kcalloc(num_pds, size, GFP_KERNEL); b45e2c927411cd Ulf Hansson 2024-10-02 227 if (!pds->pd_devs) { b45e2c927411cd Ulf Hansson 2024-10-02 228 ret = -ENOMEM; b45e2c927411cd Ulf Hansson 2024-10-02 229 goto free_pds; b45e2c927411cd Ulf Hansson 2024-10-02 230 } b45e2c927411cd Ulf Hansson 2024-10-02 231 pds->pd_links = (void *)(pds->pd_devs + num_pds); f88293625b3d04 Ulf Hansson 2024-01-26 232 f88293625b3d04 Ulf Hansson 2024-01-26 233 if (link_flags && pd_flags & PD_FLAG_DEV_LINK_ON) f88293625b3d04 Ulf Hansson 2024-01-26 234 link_flags |= DL_FLAG_RPM_ACTIVE; f88293625b3d04 Ulf Hansson 2024-01-26 235 f88293625b3d04 Ulf Hansson 2024-01-26 236 for (i = 0; i < num_pds; i++) { f88293625b3d04 Ulf Hansson 2024-01-26 237 if (by_id) f88293625b3d04 Ulf Hansson 2024-01-26 238 pd_dev = dev_pm_domain_attach_by_id(dev, i); f88293625b3d04 Ulf Hansson 2024-01-26 239 else f88293625b3d04 Ulf Hansson 2024-01-26 240 pd_dev = dev_pm_domain_attach_by_name(dev, f88293625b3d04 Ulf Hansson 2024-01-26 241 data->pd_names[i]); f88293625b3d04 Ulf Hansson 2024-01-26 242 if (IS_ERR_OR_NULL(pd_dev)) { f88293625b3d04 Ulf Hansson 2024-01-26 243 ret = pd_dev ? PTR_ERR(pd_dev) : -ENODEV; f88293625b3d04 Ulf Hansson 2024-01-26 244 goto err_attach; f88293625b3d04 Ulf Hansson 2024-01-26 245 } f88293625b3d04 Ulf Hansson 2024-01-26 246 f88293625b3d04 Ulf Hansson 2024-01-26 247 if (link_flags) { f88293625b3d04 Ulf Hansson 2024-01-26 248 struct device_link *link; f88293625b3d04 Ulf Hansson 2024-01-26 249 f88293625b3d04 Ulf Hansson 2024-01-26 250 link = device_link_add(dev, pd_dev, link_flags); f88293625b3d04 Ulf Hansson 2024-01-26 251 if (!link) { f88293625b3d04 Ulf Hansson 2024-01-26 252 ret = -ENODEV; f88293625b3d04 Ulf Hansson 2024-01-26 253 goto err_link; f88293625b3d04 Ulf Hansson 2024-01-26 254 } f88293625b3d04 Ulf Hansson 2024-01-26 255 f88293625b3d04 Ulf Hansson 2024-01-26 256 pds->pd_links[i] = link; f88293625b3d04 Ulf Hansson 2024-01-26 257 } f88293625b3d04 Ulf Hansson 2024-01-26 258 f88293625b3d04 Ulf Hansson 2024-01-26 259 pds->pd_devs[i] = pd_dev; f88293625b3d04 Ulf Hansson 2024-01-26 260 } f88293625b3d04 Ulf Hansson 2024-01-26 261 f88293625b3d04 Ulf Hansson 2024-01-26 262 pds->num_pds = num_pds; f88293625b3d04 Ulf Hansson 2024-01-26 263 *list = pds; f88293625b3d04 Ulf Hansson 2024-01-26 264 return num_pds; f88293625b3d04 Ulf Hansson 2024-01-26 265 f88293625b3d04 Ulf Hansson 2024-01-26 266 err_link: f88293625b3d04 Ulf Hansson 2024-01-26 267 dev_pm_domain_detach(pd_dev, true); f88293625b3d04 Ulf Hansson 2024-01-26 268 err_attach: f88293625b3d04 Ulf Hansson 2024-01-26 269 while (--i >= 0) { f88293625b3d04 Ulf Hansson 2024-01-26 270 if (pds->pd_links[i]) f88293625b3d04 Ulf Hansson 2024-01-26 271 device_link_del(pds->pd_links[i]); f88293625b3d04 Ulf Hansson 2024-01-26 272 dev_pm_domain_detach(pds->pd_devs[i], true); f88293625b3d04 Ulf Hansson 2024-01-26 273 } b45e2c927411cd Ulf Hansson 2024-10-02 274 kfree(pds->pd_devs); b45e2c927411cd Ulf Hansson 2024-10-02 275 free_pds: b45e2c927411cd Ulf Hansson 2024-10-02 276 kfree(pds); f88293625b3d04 Ulf Hansson 2024-01-26 277 return ret; f88293625b3d04 Ulf Hansson 2024-01-26 278 } f88293625b3d04 Ulf Hansson 2024-01-26 279 EXPORT_SYMBOL_GPL(dev_pm_domain_attach_list); f88293625b3d04 Ulf Hansson 2024-01-26 280 -- 0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki