linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: kbuild@lists.01.org, Sandeep Singh <Sandeep.Singh@amd.com>
Cc: kbuild-all@lists.01.org, jikos@kernel.org,
	benjamin.tissoires@redhat.com, linux-kernel@vger.kernel.org,
	linux-input@vger.kernel.org, srinivas.pandruvada@linux.intel.com,
	jic23@kernel.org, linux-iio@vger.kernel.org,
	Shyam-sundar.S-k@amd.com, Sandeep Singh <sandeep.singh@amd.com>,
	Nehal Shah <Nehal-bakulchandra.Shah@amd.com>
Subject: Re: [PATCH 3/4] SFH: Transport Driver to add support of AMD sensor fusion Hub (SFH)
Date: Mon, 13 Jan 2020 13:45:10 +0300	[thread overview]
Message-ID: <20200113104510.GD9488@kadam> (raw)
In-Reply-To: <1578558528-10108-1-git-send-email-Sandeep.Singh@amd.com>

Hi Sandeep,

url:    https://github.com/0day-ci/linux/commits/Sandeep-Singh/SFH-Add-Support-for-AMD-Sensor-Fusion-Hub/20200110-084435
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git b07f636fca1c8fbba124b0082487c0b3890a0e0c

If you fix the issue, kindly add following tag
Reported-by: kbuild test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>

smatch warnings:
drivers/hid/amd-sfh-hid/amdsfh-hid-client.c:157 amd_sfh_hid_client_probe() warn: possible memory leak of 'cl_dev'
drivers/hid/amd-sfh-hid/amdsfh-hid-client.c:225 amd_sfh_hid_client_remove() warn: variable dereferenced before check 'cl_dev' (see line 218)
drivers/hid/amd-sfh-hid/amdsfh-hid-client.c:225 amd_sfh_hid_client_remove() warn: variable dereferenced before check 'cl_data' (see line 220)
drivers/hid/amd-sfh-hid/amdsfh-debugfs.c:42 amdsfh_debugfs_accel_read() warn: possible memory leak of 'obuf'
drivers/hid/amd-sfh-hid/amdsfh-debugfs.c:78 amdsfh_debugfs_gyro_read() warn: possible memory leak of 'obuf'
drivers/hid/amd-sfh-hid/amdsfh-debugfs.c:114 amdsfh_debugfs_mag_read() warn: possible memory leak of 'obuf'
drivers/hid/amd-sfh-hid/amdsfh-debugfs.c:150 amdsfh_debugfs_als_read() warn: possible memory leak of 'obuf'

# https://github.com/0day-ci/linux/commit/da2b6403065dd09f90ffdd06c25cbc139acde2b8
git remote add linux-review https://github.com/0day-ci/linux
git remote update linux-review
git checkout da2b6403065dd09f90ffdd06c25cbc139acde2b8
vim +/cl_dev +157 drivers/hid/amd-sfh-hid/amdsfh-hid-client.c

da2b6403065dd0 Sandeep Singh 2020-01-09  140  static int amd_sfh_hid_client_probe(struct platform_device *pdev)
da2b6403065dd0 Sandeep Singh 2020-01-09  141  {
da2b6403065dd0 Sandeep Singh 2020-01-09  142  	struct amd_mp2_sensor_info info;
da2b6403065dd0 Sandeep Singh 2020-01-09  143  	int rc = 0;
da2b6403065dd0 Sandeep Singh 2020-01-09  144  	int i;
da2b6403065dd0 Sandeep Singh 2020-01-09  145  	struct amdtp_cl_device *cl_dev;
da2b6403065dd0 Sandeep Singh 2020-01-09  146  	struct amdtp_cl_data *cl_data;
da2b6403065dd0 Sandeep Singh 2020-01-09  147  	u32 feature_report_size = 0;
da2b6403065dd0 Sandeep Singh 2020-01-09  148  	u32 input_report_size = 0;
da2b6403065dd0 Sandeep Singh 2020-01-09  149  
da2b6403065dd0 Sandeep Singh 2020-01-09  150  	cl_dev = kzalloc(sizeof(*cl_dev), GFP_KERNEL);
da2b6403065dd0 Sandeep Singh 2020-01-09  151  	if (!cl_dev)
da2b6403065dd0 Sandeep Singh 2020-01-09  152  		return -ENOMEM;
da2b6403065dd0 Sandeep Singh 2020-01-09  153  
da2b6403065dd0 Sandeep Singh 2020-01-09  154  	cl_dev->pdev = pci_get_device(PCI_VENDOR_ID_AMD,
da2b6403065dd0 Sandeep Singh 2020-01-09  155  				      PCI_DEVICE_ID_AMD_MP2, NULL);
da2b6403065dd0 Sandeep Singh 2020-01-09  156  	if (!cl_dev->pdev)
da2b6403065dd0 Sandeep Singh 2020-01-09 @157  		return -ENOMEM;
                                                        ^^^^^^^^^^^^^^
You might want to consider using devm_kzalloc().

da2b6403065dd0 Sandeep Singh 2020-01-09  158  
da2b6403065dd0 Sandeep Singh 2020-01-09  159  	cl_data = kzalloc(sizeof(*cl_data), GFP_KERNEL);
da2b6403065dd0 Sandeep Singh 2020-01-09  160  	cl_data->num_hid_devices = amd_mp2_get_sensor_num
da2b6403065dd0 Sandeep Singh 2020-01-09  161  				   (cl_dev->pdev, &cl_data->sensor_idx[0]);
da2b6403065dd0 Sandeep Singh 2020-01-09  162  
da2b6403065dd0 Sandeep Singh 2020-01-09  163  	INIT_DELAYED_WORK(&cl_data->work, amd_sfh_work);
da2b6403065dd0 Sandeep Singh 2020-01-09  164  	INIT_DELAYED_WORK(&cl_data->work_buffer, amd_sfh_work_buffer);
da2b6403065dd0 Sandeep Singh 2020-01-09  165  	INIT_LIST_HEAD(&req_list.list);
da2b6403065dd0 Sandeep Singh 2020-01-09  166  
da2b6403065dd0 Sandeep Singh 2020-01-09  167  	amdsfh_debugfs_setup(cl_data);
da2b6403065dd0 Sandeep Singh 2020-01-09  168  
da2b6403065dd0 Sandeep Singh 2020-01-09  169  	for (i = 0; i < cl_data->num_hid_devices; i++) {
da2b6403065dd0 Sandeep Singh 2020-01-09  170  		cl_data->sensor_virt_addr[i] = dma_alloc_coherent
da2b6403065dd0 Sandeep Singh 2020-01-09  171  			(&pdev->dev, sizeof(int) * 8,
da2b6403065dd0 Sandeep Singh 2020-01-09  172  			&cl_data->sensor_phy_addr[i], GFP_KERNEL);
da2b6403065dd0 Sandeep Singh 2020-01-09  173  		cl_data->sensor_sts[i] = 0;
da2b6403065dd0 Sandeep Singh 2020-01-09  174  		cl_data->sensor_requested_cnt[i] = 0;
da2b6403065dd0 Sandeep Singh 2020-01-09  175  		cl_data->cur_hid_dev = i;
da2b6403065dd0 Sandeep Singh 2020-01-09  176  
da2b6403065dd0 Sandeep Singh 2020-01-09  177  		cl_data->report_descr_size[i] = get_descriptor_size
da2b6403065dd0 Sandeep Singh 2020-01-09  178  				(cl_data->sensor_idx[i], descr_size);
da2b6403065dd0 Sandeep Singh 2020-01-09  179  
da2b6403065dd0 Sandeep Singh 2020-01-09  180  		feature_report_size = get_descriptor_size
da2b6403065dd0 Sandeep Singh 2020-01-09  181  				(cl_data->sensor_idx[i], feature_size);
da2b6403065dd0 Sandeep Singh 2020-01-09  182  
da2b6403065dd0 Sandeep Singh 2020-01-09  183  		input_report_size =  get_descriptor_size
da2b6403065dd0 Sandeep Singh 2020-01-09  184  			(cl_data->sensor_idx[i], input_size);
da2b6403065dd0 Sandeep Singh 2020-01-09  185  
da2b6403065dd0 Sandeep Singh 2020-01-09  186  		cl_data->feature_report[i] = kzalloc(feature_report_size,
da2b6403065dd0 Sandeep Singh 2020-01-09  187  						     GFP_KERNEL);
da2b6403065dd0 Sandeep Singh 2020-01-09  188  		cl_data->input_report[i] = kzalloc(input_report_size,
da2b6403065dd0 Sandeep Singh 2020-01-09  189  						   GFP_KERNEL);
da2b6403065dd0 Sandeep Singh 2020-01-09  190  		info.period = PERIOD;
da2b6403065dd0 Sandeep Singh 2020-01-09  191  		info.sensor_idx = cl_data->sensor_idx[i];
da2b6403065dd0 Sandeep Singh 2020-01-09  192  		info.phy_address = cl_data->sensor_phy_addr[i];
da2b6403065dd0 Sandeep Singh 2020-01-09  193  		cl_data->report_descr[i] = kzalloc
da2b6403065dd0 Sandeep Singh 2020-01-09  194  			(cl_data->report_descr_size[i], GFP_KERNEL);
da2b6403065dd0 Sandeep Singh 2020-01-09  195  		if (!cl_data->report_descr[i])
da2b6403065dd0 Sandeep Singh 2020-01-09  196  			return -ENOMEM;
da2b6403065dd0 Sandeep Singh 2020-01-09  197  		rc = get_report_descriptor(cl_data->sensor_idx[i],
da2b6403065dd0 Sandeep Singh 2020-01-09  198  					   cl_data->report_descr[i]);
da2b6403065dd0 Sandeep Singh 2020-01-09  199  		rc = amdtp_hid_probe(cl_data->cur_hid_dev, cl_data);
da2b6403065dd0 Sandeep Singh 2020-01-09  200  		rc = amd_start_sensor(cl_dev->pdev, info);
da2b6403065dd0 Sandeep Singh 2020-01-09  201  			cl_data->sensor_sts[i] = 1;
da2b6403065dd0 Sandeep Singh 2020-01-09  202  	}
da2b6403065dd0 Sandeep Singh 2020-01-09  203  
da2b6403065dd0 Sandeep Singh 2020-01-09  204  	cl_dev->cl_data = cl_data;
da2b6403065dd0 Sandeep Singh 2020-01-09  205  	cl_data_context = cl_data;
da2b6403065dd0 Sandeep Singh 2020-01-09  206  	platform_set_drvdata(pdev, cl_dev);
da2b6403065dd0 Sandeep Singh 2020-01-09  207  	schedule_delayed_work(&cl_data->work_buffer, PERIOD);
da2b6403065dd0 Sandeep Singh 2020-01-09  208  	return 0;
da2b6403065dd0 Sandeep Singh 2020-01-09  209  }
da2b6403065dd0 Sandeep Singh 2020-01-09  210  
da2b6403065dd0 Sandeep Singh 2020-01-09  211  static int amd_sfh_hid_client_remove(struct platform_device *pdev)
da2b6403065dd0 Sandeep Singh 2020-01-09  212  {
da2b6403065dd0 Sandeep Singh 2020-01-09  213  	int i;
da2b6403065dd0 Sandeep Singh 2020-01-09  214  	struct amdtp_cl_device *cl_dev;
da2b6403065dd0 Sandeep Singh 2020-01-09  215  	struct amdtp_cl_data *cl_data;
da2b6403065dd0 Sandeep Singh 2020-01-09  216  
da2b6403065dd0 Sandeep Singh 2020-01-09  217  	cl_dev = platform_get_drvdata(pdev);
da2b6403065dd0 Sandeep Singh 2020-01-09 @218  	cl_data = cl_dev->cl_data;
da2b6403065dd0 Sandeep Singh 2020-01-09  219  
da2b6403065dd0 Sandeep Singh 2020-01-09 @220  	for (i = 0; i < cl_data->num_hid_devices; i++)
da2b6403065dd0 Sandeep Singh 2020-01-09  221  		amd_stop_sensor(cl_dev->pdev, i);
da2b6403065dd0 Sandeep Singh 2020-01-09  222  	cancel_delayed_work_sync(&cl_data->work);
da2b6403065dd0 Sandeep Singh 2020-01-09  223  	cancel_delayed_work_sync(&cl_data->work_buffer);
da2b6403065dd0 Sandeep Singh 2020-01-09  224  	amdsfh_debugfs_destroy(cl_data);
da2b6403065dd0 Sandeep Singh 2020-01-09 @225  	if (cl_dev && cl_data)
                                                    ^^^^^^    ^^^^^^^
If these are NULL, it's too late.

da2b6403065dd0 Sandeep Singh 2020-01-09  226  		amdtp_hid_remove(cl_data);
da2b6403065dd0 Sandeep Singh 2020-01-09  227  
da2b6403065dd0 Sandeep Singh 2020-01-09  228  	for (i = 0; i < cl_data->num_hid_devices; i++) {
da2b6403065dd0 Sandeep Singh 2020-01-09  229  		if (cl_data->sensor_virt_addr[i])
da2b6403065dd0 Sandeep Singh 2020-01-09  230  			dma_free_coherent(&pdev->dev, 8 * sizeof(int),
da2b6403065dd0 Sandeep Singh 2020-01-09  231  					  cl_data->sensor_virt_addr[i],
da2b6403065dd0 Sandeep Singh 2020-01-09  232  					  cl_data->sensor_phy_addr[i]);
da2b6403065dd0 Sandeep Singh 2020-01-09  233  	}
da2b6403065dd0 Sandeep Singh 2020-01-09  234  
da2b6403065dd0 Sandeep Singh 2020-01-09  235  	kfree(cl_data);
da2b6403065dd0 Sandeep Singh 2020-01-09  236  	pr_info("%s:%s Exit\n", DRIVER_NAME, __func__);
da2b6403065dd0 Sandeep Singh 2020-01-09  237  	return 0;
da2b6403065dd0 Sandeep Singh 2020-01-09  238  }

---
0-DAY kernel test infrastructure                 Open Source Technology Center
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org Intel Corporation

  reply	other threads:[~2020-01-13 10:45 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-09  8:21 [PATCH 0/4] SFH: Add Support for AMD Sensor Fusion Hub Sandeep Singh
2020-01-09  8:27 ` [PATCH 1/4] SFH: Add maintainer list and documentation for AMD SFH based on HID framework Sandeep Singh
2020-01-09  8:28 ` [PATCH 2/4] SFH: PCI driver to add support of AMD sensor fusion Hub using " Sandeep Singh
2020-01-11  0:37   ` kbuild test robot
2020-01-09  8:28 ` [PATCH 3/4] SFH: Transport Driver to add support of AMD sensor fusion Hub (SFH) Sandeep Singh
2020-01-13 10:45   ` Dan Carpenter [this message]
2020-01-09  8:29 ` [PATCH 4/4] SFH: Create HID report to Enable " Sandeep Singh

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200113104510.GD9488@kadam \
    --to=dan.carpenter@oracle.com \
    --cc=Nehal-bakulchandra.Shah@amd.com \
    --cc=Sandeep.Singh@amd.com \
    --cc=Shyam-sundar.S-k@amd.com \
    --cc=benjamin.tissoires@redhat.com \
    --cc=jic23@kernel.org \
    --cc=jikos@kernel.org \
    --cc=kbuild-all@lists.01.org \
    --cc=kbuild@lists.01.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=srinivas.pandruvada@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).