Re: [PATCH v2 5/8] Bluetooth: Add initial implementation of BIS connections

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

 



Hi Luiz,

url:    https://github.com/intel-lab-lkp/linux/commits/Luiz-Augusto-von-Dentz/Bluetooth-eir-Add-helpers-for-managing-service-data/20220507-060014
base:   https://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next.git master
config: csky-randconfig-m031-20220508 (https://download.01.org/0day-ci/archive/20220512/202205121532.jtQf7nFA-lkp@xxxxxxxxx/config)
compiler: csky-linux-gcc (GCC) 11.3.0

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

New smatch warnings:
net/bluetooth/hci_sync.c:1110 hci_start_per_adv_sync() warn: passing zero to 'PTR_ERR'

vim +/PTR_ERR +1110 net/bluetooth/hci_sync.c

2f80269de71810 Luiz Augusto von Dentz 2022-05-06  1091  int hci_start_per_adv_sync(struct hci_dev *hdev, u8 instance, u8 data_len,
2f80269de71810 Luiz Augusto von Dentz 2022-05-06  1092  			   u8 *data, u32 flags, u16 min_interval,
2f80269de71810 Luiz Augusto von Dentz 2022-05-06  1093  			   u16 max_interval, u16 sync_interval)
2f80269de71810 Luiz Augusto von Dentz 2022-05-06  1094  {
2f80269de71810 Luiz Augusto von Dentz 2022-05-06  1095  	struct adv_info *adv = NULL;
2f80269de71810 Luiz Augusto von Dentz 2022-05-06  1096  	int err;
2f80269de71810 Luiz Augusto von Dentz 2022-05-06  1097  	bool added = false;
2f80269de71810 Luiz Augusto von Dentz 2022-05-06  1098  
2f80269de71810 Luiz Augusto von Dentz 2022-05-06  1099  	hci_disable_per_advertising_sync(hdev, instance);
2f80269de71810 Luiz Augusto von Dentz 2022-05-06  1100  
2f80269de71810 Luiz Augusto von Dentz 2022-05-06  1101  	if (instance) {
2f80269de71810 Luiz Augusto von Dentz 2022-05-06  1102  		adv = hci_find_adv_instance(hdev, instance);
2f80269de71810 Luiz Augusto von Dentz 2022-05-06  1103  		/* Create an instance if that could not be found */
2f80269de71810 Luiz Augusto von Dentz 2022-05-06  1104  		if (!adv) {
2f80269de71810 Luiz Augusto von Dentz 2022-05-06  1105  			adv = hci_add_per_instance(hdev, instance, flags,
2f80269de71810 Luiz Augusto von Dentz 2022-05-06  1106  						   data_len, data,
2f80269de71810 Luiz Augusto von Dentz 2022-05-06  1107  						   sync_interval,
2f80269de71810 Luiz Augusto von Dentz 2022-05-06  1108  						   sync_interval);
2f80269de71810 Luiz Augusto von Dentz 2022-05-06  1109  			if (IS_ERR_OR_NULL(adv))
2f80269de71810 Luiz Augusto von Dentz 2022-05-06 @1110  				return PTR_ERR(adv);

If hci_add_per_instance() returns NULL then do we really want to return
success here?

When functions return both error pointers and NULL, the NULL means the
feature has been disabled deliberately.  So, for example, some people
like blinking LED lights but others do not want them.

	p = get_blinking_lights();

If there is an allocation failure or some kind of an error then p is
an error pointer.  We have to return that error to the user.  It might
seem like a small thing to us, but maybe it's important to them for some
reason so we can't just ignore their desire for blinking lights.  We
have to handle that error properly so they can fix the issue and retry.
However if p is NULL then don't print a warning message, and don't
return an error.  All the surrounding code has to be written to support
that blinking lights are optional.

The hci_add_per_instance() function is not optional and it cannot return
NULL.

There are some examples where this is done incorrectly.  Sometimes
people think checking for NULL is just safer because they assume people
will add bugs to hci_add_per_instance() so that it returns the wrong
thing.  This occasionally does happen.  I fixed a bug earlier this week.
But we generally don't work around bugs, we just fix them.

There is another code which returns ERR_PTR(-EINVAL) when the feature is
disabled.  It also returns -EINVAL for other errors.  The callers have
to do something like:

	p = get_feature();
	if (p == ERR_PTR(-EINVAL))
		p = NULL;
	if (IS_ERR(p))
		return PTR_ERR(p);

So not everything conforms to the guidelines.

2f80269de71810 Luiz Augusto von Dentz 2022-05-06  1111  			added = true;
2f80269de71810 Luiz Augusto von Dentz 2022-05-06  1112  		}
2f80269de71810 Luiz Augusto von Dentz 2022-05-06  1113  	}
2f80269de71810 Luiz Augusto von Dentz 2022-05-06  1114  
2f80269de71810 Luiz Augusto von Dentz 2022-05-06  1115  	/* Only start advertising if instance 0 or if a dedicated instance has
2f80269de71810 Luiz Augusto von Dentz 2022-05-06  1116  	 * been added.
2f80269de71810 Luiz Augusto von Dentz 2022-05-06  1117  	 */
2f80269de71810 Luiz Augusto von Dentz 2022-05-06  1118  	if (!adv || added) {
2f80269de71810 Luiz Augusto von Dentz 2022-05-06  1119  		err = hci_start_ext_adv_sync(hdev, instance);
2f80269de71810 Luiz Augusto von Dentz 2022-05-06  1120  		if (err < 0)
2f80269de71810 Luiz Augusto von Dentz 2022-05-06  1121  			goto fail;
2f80269de71810 Luiz Augusto von Dentz 2022-05-06  1122  
2f80269de71810 Luiz Augusto von Dentz 2022-05-06  1123  		err = hci_adv_bcast_annoucement(hdev, adv);
2f80269de71810 Luiz Augusto von Dentz 2022-05-06  1124  		if (err < 0)
2f80269de71810 Luiz Augusto von Dentz 2022-05-06  1125  			goto fail;
2f80269de71810 Luiz Augusto von Dentz 2022-05-06  1126  	}
2f80269de71810 Luiz Augusto von Dentz 2022-05-06  1127  
2f80269de71810 Luiz Augusto von Dentz 2022-05-06  1128  	err = hci_set_per_adv_params_sync(hdev, instance, min_interval,
2f80269de71810 Luiz Augusto von Dentz 2022-05-06  1129  					  max_interval);
2f80269de71810 Luiz Augusto von Dentz 2022-05-06  1130  	if (err < 0)
2f80269de71810 Luiz Augusto von Dentz 2022-05-06  1131  		goto fail;
2f80269de71810 Luiz Augusto von Dentz 2022-05-06  1132  
2f80269de71810 Luiz Augusto von Dentz 2022-05-06  1133  	err = hci_set_per_adv_data_sync(hdev, instance);
2f80269de71810 Luiz Augusto von Dentz 2022-05-06  1134  	if (err < 0)
2f80269de71810 Luiz Augusto von Dentz 2022-05-06  1135  		goto fail;
2f80269de71810 Luiz Augusto von Dentz 2022-05-06  1136  
2f80269de71810 Luiz Augusto von Dentz 2022-05-06  1137  	err = hci_enable_per_advertising_sync(hdev, instance);
2f80269de71810 Luiz Augusto von Dentz 2022-05-06  1138  	if (err < 0)
2f80269de71810 Luiz Augusto von Dentz 2022-05-06  1139  		goto fail;
2f80269de71810 Luiz Augusto von Dentz 2022-05-06  1140  
2f80269de71810 Luiz Augusto von Dentz 2022-05-06  1141  	return 0;
2f80269de71810 Luiz Augusto von Dentz 2022-05-06  1142  
2f80269de71810 Luiz Augusto von Dentz 2022-05-06  1143  fail:
2f80269de71810 Luiz Augusto von Dentz 2022-05-06  1144  	if (added)
2f80269de71810 Luiz Augusto von Dentz 2022-05-06  1145  		hci_remove_adv_instance(hdev, instance);
2f80269de71810 Luiz Augusto von Dentz 2022-05-06  1146  
2f80269de71810 Luiz Augusto von Dentz 2022-05-06  1147  	return err;
2f80269de71810 Luiz Augusto von Dentz 2022-05-06  1148  }

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




[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux