[linux-next:master 12341/13934] drivers/thermal/k3_j72xx_bandgap.c:521 k3_j72xx_bandgap_probe() warn: possible memory leak of 'ref_table'

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



tree:   https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git master
head:   cc63e8e92cb872081f249ea16e6c460642f3e4fb
commit: ffcb2fc86eb7ebc9f5524525fb57e1cccfbd1fc0 [12341/13934] thermal: k3_j72xx_bandgap: Add the bandgap driver support
config: openrisc-randconfig-m031-20220523 (https://download.01.org/0day-ci/archive/20220524/202205241527.HnmfEBAn-lkp@xxxxxxxxx/config)
compiler: or1k-linux-gcc (GCC) 11.3.0

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <lkp@xxxxxxxxx>
Reported-by: Dan Carpenter <dan.carpenter@xxxxxxxxxx>

smatch warnings:
drivers/thermal/k3_j72xx_bandgap.c:521 k3_j72xx_bandgap_probe() warn: possible memory leak of 'ref_table'

vim +/ref_table +521 drivers/thermal/k3_j72xx_bandgap.c

ffcb2fc86eb7eb Keerthy 2022-05-17  355  static int k3_j72xx_bandgap_probe(struct platform_device *pdev)
ffcb2fc86eb7eb Keerthy 2022-05-17  356  {
ffcb2fc86eb7eb Keerthy 2022-05-17  357  	int ret = 0, cnt, val, id;
ffcb2fc86eb7eb Keerthy 2022-05-17  358  	int high_max, low_temp;
ffcb2fc86eb7eb Keerthy 2022-05-17  359  	struct resource *res;
ffcb2fc86eb7eb Keerthy 2022-05-17  360  	struct device *dev = &pdev->dev;
ffcb2fc86eb7eb Keerthy 2022-05-17  361  	struct k3_j72xx_bandgap *bgp;
ffcb2fc86eb7eb Keerthy 2022-05-17  362  	struct k3_thermal_data *data;
ffcb2fc86eb7eb Keerthy 2022-05-17  363  	int workaround_needed = 0;
ffcb2fc86eb7eb Keerthy 2022-05-17  364  	const struct k3_j72xx_bandgap_data *driver_data;
ffcb2fc86eb7eb Keerthy 2022-05-17  365  	struct thermal_zone_device *ti_thermal;
ffcb2fc86eb7eb Keerthy 2022-05-17  366  	int *ref_table;
ffcb2fc86eb7eb Keerthy 2022-05-17  367  	struct err_values err_vals;
ffcb2fc86eb7eb Keerthy 2022-05-17  368  
ffcb2fc86eb7eb Keerthy 2022-05-17  369  	const s64 golden_factors[] = {
ffcb2fc86eb7eb Keerthy 2022-05-17  370  		-490019999999999936,
ffcb2fc86eb7eb Keerthy 2022-05-17  371  		3251200000000000,
ffcb2fc86eb7eb Keerthy 2022-05-17  372  		-1705800000000,
ffcb2fc86eb7eb Keerthy 2022-05-17  373  		603730000,
ffcb2fc86eb7eb Keerthy 2022-05-17  374  		-92627,
ffcb2fc86eb7eb Keerthy 2022-05-17  375  	};
ffcb2fc86eb7eb Keerthy 2022-05-17  376  
ffcb2fc86eb7eb Keerthy 2022-05-17  377  	const s64 pvt_wa_factors[] = {
ffcb2fc86eb7eb Keerthy 2022-05-17  378  		-415230000000000000,
ffcb2fc86eb7eb Keerthy 2022-05-17  379  		3126600000000000,
ffcb2fc86eb7eb Keerthy 2022-05-17  380  		-1157800000000,
ffcb2fc86eb7eb Keerthy 2022-05-17  381  	};
ffcb2fc86eb7eb Keerthy 2022-05-17  382  
ffcb2fc86eb7eb Keerthy 2022-05-17  383  	bgp = devm_kzalloc(&pdev->dev, sizeof(*bgp), GFP_KERNEL);
ffcb2fc86eb7eb Keerthy 2022-05-17  384  	if (!bgp)
ffcb2fc86eb7eb Keerthy 2022-05-17  385  		return -ENOMEM;
ffcb2fc86eb7eb Keerthy 2022-05-17  386  
ffcb2fc86eb7eb Keerthy 2022-05-17  387  	bgp->dev = dev;
ffcb2fc86eb7eb Keerthy 2022-05-17  388  	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
ffcb2fc86eb7eb Keerthy 2022-05-17  389  	bgp->base = devm_ioremap_resource(dev, res);
ffcb2fc86eb7eb Keerthy 2022-05-17  390  	if (IS_ERR(bgp->base))
ffcb2fc86eb7eb Keerthy 2022-05-17  391  		return PTR_ERR(bgp->base);
ffcb2fc86eb7eb Keerthy 2022-05-17  392  
ffcb2fc86eb7eb Keerthy 2022-05-17  393  	res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
ffcb2fc86eb7eb Keerthy 2022-05-17  394  	bgp->cfg2_base = devm_ioremap_resource(dev, res);
ffcb2fc86eb7eb Keerthy 2022-05-17  395  	if (IS_ERR(bgp->cfg2_base))
ffcb2fc86eb7eb Keerthy 2022-05-17  396  		return PTR_ERR(bgp->cfg2_base);
ffcb2fc86eb7eb Keerthy 2022-05-17  397  
ffcb2fc86eb7eb Keerthy 2022-05-17  398  	res = platform_get_resource(pdev, IORESOURCE_MEM, 2);
ffcb2fc86eb7eb Keerthy 2022-05-17  399  	bgp->fuse_base = devm_ioremap_resource(dev, res);
ffcb2fc86eb7eb Keerthy 2022-05-17  400  	if (IS_ERR(bgp->fuse_base))
ffcb2fc86eb7eb Keerthy 2022-05-17  401  		return PTR_ERR(bgp->fuse_base);
ffcb2fc86eb7eb Keerthy 2022-05-17  402  
ffcb2fc86eb7eb Keerthy 2022-05-17  403  	driver_data = of_device_get_match_data(dev);
ffcb2fc86eb7eb Keerthy 2022-05-17  404  	if (driver_data)
ffcb2fc86eb7eb Keerthy 2022-05-17  405  		workaround_needed = driver_data->has_errata_i2128;
ffcb2fc86eb7eb Keerthy 2022-05-17  406  
ffcb2fc86eb7eb Keerthy 2022-05-17  407  	pm_runtime_enable(dev);
ffcb2fc86eb7eb Keerthy 2022-05-17  408  	ret = pm_runtime_get_sync(dev);
ffcb2fc86eb7eb Keerthy 2022-05-17  409  	if (ret < 0) {
ffcb2fc86eb7eb Keerthy 2022-05-17  410  		pm_runtime_put_noidle(dev);
ffcb2fc86eb7eb Keerthy 2022-05-17  411  		pm_runtime_disable(dev);
ffcb2fc86eb7eb Keerthy 2022-05-17  412  		return ret;
ffcb2fc86eb7eb Keerthy 2022-05-17  413  	}
ffcb2fc86eb7eb Keerthy 2022-05-17  414  
ffcb2fc86eb7eb Keerthy 2022-05-17  415  	/* Get the sensor count in the VTM */
ffcb2fc86eb7eb Keerthy 2022-05-17  416  	val = readl(bgp->base + K3_VTM_DEVINFO_PWR0_OFFSET);
ffcb2fc86eb7eb Keerthy 2022-05-17  417  	cnt = val & K3_VTM_DEVINFO_PWR0_TEMPSENS_CT_MASK;
ffcb2fc86eb7eb Keerthy 2022-05-17  418  	cnt >>= __ffs(K3_VTM_DEVINFO_PWR0_TEMPSENS_CT_MASK);
ffcb2fc86eb7eb Keerthy 2022-05-17  419  
ffcb2fc86eb7eb Keerthy 2022-05-17  420  	data = devm_kcalloc(bgp->dev, cnt, sizeof(*data), GFP_KERNEL);
ffcb2fc86eb7eb Keerthy 2022-05-17  421  	if (!data) {
ffcb2fc86eb7eb Keerthy 2022-05-17  422  		ret = -ENOMEM;
ffcb2fc86eb7eb Keerthy 2022-05-17  423  		goto err_alloc;
ffcb2fc86eb7eb Keerthy 2022-05-17  424  	}
ffcb2fc86eb7eb Keerthy 2022-05-17  425  
ffcb2fc86eb7eb Keerthy 2022-05-17  426  	ref_table = kzalloc(sizeof(*ref_table) * TABLE_SIZE, GFP_KERNEL);
ffcb2fc86eb7eb Keerthy 2022-05-17  427  	if (!ref_table) {
ffcb2fc86eb7eb Keerthy 2022-05-17  428  		ret = -ENOMEM;
ffcb2fc86eb7eb Keerthy 2022-05-17  429  		goto err_alloc;
ffcb2fc86eb7eb Keerthy 2022-05-17  430  	}
ffcb2fc86eb7eb Keerthy 2022-05-17  431  
ffcb2fc86eb7eb Keerthy 2022-05-17  432  	derived_table = devm_kzalloc(bgp->dev, sizeof(*derived_table) * TABLE_SIZE,
ffcb2fc86eb7eb Keerthy 2022-05-17  433  				     GFP_KERNEL);
ffcb2fc86eb7eb Keerthy 2022-05-17  434  	if (!derived_table) {
ffcb2fc86eb7eb Keerthy 2022-05-17  435  		ret = -ENOMEM;
ffcb2fc86eb7eb Keerthy 2022-05-17  436  		goto err_alloc;
ffcb2fc86eb7eb Keerthy 2022-05-17  437  	}
ffcb2fc86eb7eb Keerthy 2022-05-17  438  
ffcb2fc86eb7eb Keerthy 2022-05-17  439  	/* Workaround not needed if bit30/bit31 is set even for J721e */
ffcb2fc86eb7eb Keerthy 2022-05-17  440  	if (workaround_needed && (readl(bgp->fuse_base + 0x0) & 0xc0000000) == 0xc0000000)
ffcb2fc86eb7eb Keerthy 2022-05-17  441  		workaround_needed = false;
ffcb2fc86eb7eb Keerthy 2022-05-17  442  
ffcb2fc86eb7eb Keerthy 2022-05-17  443  	dev_dbg(bgp->dev, "Work around %sneeded\n",
ffcb2fc86eb7eb Keerthy 2022-05-17  444  		workaround_needed ? "not " : "");
ffcb2fc86eb7eb Keerthy 2022-05-17  445  
ffcb2fc86eb7eb Keerthy 2022-05-17  446  	if (!workaround_needed)
ffcb2fc86eb7eb Keerthy 2022-05-17  447  		init_table(5, ref_table, golden_factors);
ffcb2fc86eb7eb Keerthy 2022-05-17  448  	else
ffcb2fc86eb7eb Keerthy 2022-05-17  449  		init_table(3, ref_table, pvt_wa_factors);
ffcb2fc86eb7eb Keerthy 2022-05-17  450  
ffcb2fc86eb7eb Keerthy 2022-05-17  451  	/* Register the thermal sensors */
ffcb2fc86eb7eb Keerthy 2022-05-17  452  	for (id = 0; id < cnt; id++) {
ffcb2fc86eb7eb Keerthy 2022-05-17  453  		data[id].bgp = bgp;
ffcb2fc86eb7eb Keerthy 2022-05-17  454  		data[id].ctrl_offset = K3_VTM_TMPSENS0_CTRL_OFFSET + id * 0x20;
ffcb2fc86eb7eb Keerthy 2022-05-17  455  		data[id].stat_offset = data[id].ctrl_offset +
ffcb2fc86eb7eb Keerthy 2022-05-17  456  					K3_VTM_TMPSENS_STAT_OFFSET;
ffcb2fc86eb7eb Keerthy 2022-05-17  457  
ffcb2fc86eb7eb Keerthy 2022-05-17  458  		if (workaround_needed) {
ffcb2fc86eb7eb Keerthy 2022-05-17  459  			/* ref adc values for -40C, 30C & 125C respectively */
ffcb2fc86eb7eb Keerthy 2022-05-17  460  			err_vals.refs[0] = MINUS40CREF;
ffcb2fc86eb7eb Keerthy 2022-05-17  461  			err_vals.refs[1] = PLUS30CREF;
ffcb2fc86eb7eb Keerthy 2022-05-17  462  			err_vals.refs[2] = PLUS125CREF;
ffcb2fc86eb7eb Keerthy 2022-05-17  463  			err_vals.refs[3] = PLUS150CREF;
ffcb2fc86eb7eb Keerthy 2022-05-17  464  			get_efuse_values(id, &data[id], err_vals.errs, bgp);
ffcb2fc86eb7eb Keerthy 2022-05-17  465  		}
ffcb2fc86eb7eb Keerthy 2022-05-17  466  
ffcb2fc86eb7eb Keerthy 2022-05-17  467  		if (id == 0 && workaround_needed)
ffcb2fc86eb7eb Keerthy 2022-05-17  468  			prep_lookup_table(&err_vals, ref_table);
ffcb2fc86eb7eb Keerthy 2022-05-17  469  		else if (id == 0 && !workaround_needed)
ffcb2fc86eb7eb Keerthy 2022-05-17  470  			memcpy(derived_table, ref_table, TABLE_SIZE * 4);
ffcb2fc86eb7eb Keerthy 2022-05-17  471  
ffcb2fc86eb7eb Keerthy 2022-05-17  472  		val = readl(data[id].bgp->cfg2_base + data[id].ctrl_offset);
ffcb2fc86eb7eb Keerthy 2022-05-17  473  		val |= (K3_VTM_TMPSENS_CTRL_MAXT_OUTRG_EN |
ffcb2fc86eb7eb Keerthy 2022-05-17  474  			K3_VTM_TMPSENS_CTRL_SOC |
ffcb2fc86eb7eb Keerthy 2022-05-17  475  			K3_VTM_TMPSENS_CTRL_CLRZ | BIT(4));
ffcb2fc86eb7eb Keerthy 2022-05-17  476  		writel(val, data[id].bgp->cfg2_base + data[id].ctrl_offset);
ffcb2fc86eb7eb Keerthy 2022-05-17  477  
ffcb2fc86eb7eb Keerthy 2022-05-17  478  		bgp->ts_data[id] = &data[id];
ffcb2fc86eb7eb Keerthy 2022-05-17  479  		ti_thermal =
ffcb2fc86eb7eb Keerthy 2022-05-17  480  		devm_thermal_zone_of_sensor_register(bgp->dev, id,
ffcb2fc86eb7eb Keerthy 2022-05-17  481  						     &data[id],
ffcb2fc86eb7eb Keerthy 2022-05-17  482  						     &k3_of_thermal_ops);
ffcb2fc86eb7eb Keerthy 2022-05-17  483  		if (IS_ERR(ti_thermal)) {
ffcb2fc86eb7eb Keerthy 2022-05-17  484  			dev_err(bgp->dev, "thermal zone device is NULL\n");
ffcb2fc86eb7eb Keerthy 2022-05-17  485  			ret = PTR_ERR(ti_thermal);
ffcb2fc86eb7eb Keerthy 2022-05-17  486  			goto err_alloc;
ffcb2fc86eb7eb Keerthy 2022-05-17  487  		}
ffcb2fc86eb7eb Keerthy 2022-05-17  488  	}
ffcb2fc86eb7eb Keerthy 2022-05-17  489  
ffcb2fc86eb7eb Keerthy 2022-05-17  490  	/*
ffcb2fc86eb7eb Keerthy 2022-05-17  491  	 * Program TSHUT thresholds
ffcb2fc86eb7eb Keerthy 2022-05-17  492  	 * Step 1: set the thresholds to ~123C and 105C WKUP_VTM_MISC_CTRL2
ffcb2fc86eb7eb Keerthy 2022-05-17  493  	 * Step 2: WKUP_VTM_TMPSENS_CTRL_j set the MAXT_OUTRG_EN  bit
ffcb2fc86eb7eb Keerthy 2022-05-17  494  	 *         This is already taken care as per of init
ffcb2fc86eb7eb Keerthy 2022-05-17  495  	 * Step 3: WKUP_VTM_MISC_CTRL set the ANYMAXT_OUTRG_ALERT_EN  bit
ffcb2fc86eb7eb Keerthy 2022-05-17  496  	 */
ffcb2fc86eb7eb Keerthy 2022-05-17  497  	high_max = k3_j72xx_bandgap_temp_to_adc_code(MAX_TEMP);
ffcb2fc86eb7eb Keerthy 2022-05-17  498  	low_temp = k3_j72xx_bandgap_temp_to_adc_code(COOL_DOWN_TEMP);
ffcb2fc86eb7eb Keerthy 2022-05-17  499  
ffcb2fc86eb7eb Keerthy 2022-05-17  500  	writel((low_temp << 16) | high_max, data[0].bgp->cfg2_base +
ffcb2fc86eb7eb Keerthy 2022-05-17  501  	       K3_VTM_MISC_CTRL2_OFFSET);
ffcb2fc86eb7eb Keerthy 2022-05-17  502  	mdelay(100);
ffcb2fc86eb7eb Keerthy 2022-05-17  503  	writel(K3_VTM_ANYMAXT_OUTRG_ALERT_EN, data[0].bgp->cfg2_base +
ffcb2fc86eb7eb Keerthy 2022-05-17  504  	       K3_VTM_MISC_CTRL_OFFSET);
ffcb2fc86eb7eb Keerthy 2022-05-17  505  
ffcb2fc86eb7eb Keerthy 2022-05-17  506  	platform_set_drvdata(pdev, bgp);
ffcb2fc86eb7eb Keerthy 2022-05-17  507  
ffcb2fc86eb7eb Keerthy 2022-05-17  508  	print_look_up_table(dev, ref_table);
ffcb2fc86eb7eb Keerthy 2022-05-17  509  	/*
ffcb2fc86eb7eb Keerthy 2022-05-17  510  	 * Now that the derived_table has the appropriate look up values
ffcb2fc86eb7eb Keerthy 2022-05-17  511  	 * Free up the ref_table
ffcb2fc86eb7eb Keerthy 2022-05-17  512  	 */
ffcb2fc86eb7eb Keerthy 2022-05-17  513  	kfree(ref_table);
ffcb2fc86eb7eb Keerthy 2022-05-17  514  
ffcb2fc86eb7eb Keerthy 2022-05-17  515  	return 0;
ffcb2fc86eb7eb Keerthy 2022-05-17  516  
ffcb2fc86eb7eb Keerthy 2022-05-17  517  err_alloc:
ffcb2fc86eb7eb Keerthy 2022-05-17  518  	pm_runtime_put_sync(&pdev->dev);
ffcb2fc86eb7eb Keerthy 2022-05-17  519  	pm_runtime_disable(&pdev->dev);
ffcb2fc86eb7eb Keerthy 2022-05-17  520  
ffcb2fc86eb7eb Keerthy 2022-05-17 @521  	return ret;

kfree(ref_table) is leaked.

ffcb2fc86eb7eb Keerthy 2022-05-17  522  }

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp





[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux