s2e/source/s2e-linux-kernel/linux-4.9.3/drivers/hid/hid-sensor-hub.c
/*
 * Handle raw report as sent by device
 */
Handle raw report as sent by device
Handle raw report as sent by device
static int sensor_hub_raw_event(struct hid_device *hdev,
		struct hid_report *report, u8 *raw_data, int size)
{
	int i;
	u8 *ptr;
	int sz;
	struct sensor_hub_data *pdata = hid_get_drvdata(hdev);
	unsigned long flags;
	struct hid_sensor_hub_callbacks *callback = NULL;
	struct hid_collection *collection = NULL;
	void *priv = NULL;
	struct hid_sensor_hub_device *hsdev = NULL;
	hid_dbg(hdev, "sensor_hub_raw_event report id:0x%x size:%d type:%d\n",
			 report->id, size, report->type);
	hid_dbg(hdev, "maxfield:%d\n", report->maxfield);
	if (report->type != HID_INPUT_REPORT)
		return 1;
	ptr = raw_data;
	ptr++; 
	spin_lock_irqsave(&pdata->lock, flags);
	for (i = 0; i < report->maxfield; ++i) {
		hid_dbg(hdev, "%d collection_index:%x hid:%x sz:%x\n",
				i, report->field[i]->usage->collection_index,
				report->field[i]->usage->hid,
				(report->field[i]->report_size *
					report->field[i]->report_count)/8);
		sz = (report->field[i]->report_size *
					report->field[i]->report_count)/8;
		collection = &hdev->collection[
				report->field[i]->usage->collection_index];
		hid_dbg(hdev, "collection->usage %x\n",
					collection->usage);
		callback = sensor_hub_get_callback(hdev,
				report->field[i]->physical,
				report->field[i]->usage[0].collection_index,
				&hsdev, &priv);
		if (!callback) {
			ptr += sz;
			continue;
		}
		if (hsdev->pending.status && (hsdev->pending.attr_usage_id ==
					      report->field[i]->usage->hid ||
					      hsdev->pending.attr_usage_id ==
					      report->field[i]->logical)) {
			hid_dbg(hdev, "data was pending ...\n");
			hsdev->pending.raw_data = kmemdup(ptr, sz, GFP_ATOMIC);
			if (hsdev->pending.raw_data)
				hsdev->pending.raw_size = sz;
			else
				hsdev->pending.raw_size = 0;
			complete(&hsdev->pending.ready);
		}
		if (callback->capture_sample) {
			if (report->field[i]->logical)
				callback->capture_sample(hsdev,
					report->field[i]->logical, sz, ptr,
					callback->pdev);
			else
				callback->capture_sample(hsdev,
					report->field[i]->usage->hid, sz, ptr,
					callback->pdev);
		}
		ptr += sz;
	}
	if (callback && collection && callback->send_event)
		callback->send_event(hsdev, collection->usage,
				callback->pdev);
	spin_unlock_irqrestore(&pdata->lock, flags);
	return 1;
}
static int sensor_hub_raw_event ( struct hid_device * hdev , struct hid_report * report , u8 * raw_data , int size ) { int i ; u8 * ptr ; int sz ; struct sensor_hub_data * pdata = hid_get_drvdata ( hdev ) ; unsigned long flags ; struct hid_sensor_hub_callbacks * callback = NULL ; struct hid_collection * collection = NULL ; void * priv = NULL ; struct hid_sensor_hub_device * hsdev = NULL ; hid_dbg ( hdev , " \n " , report -> id , size , report -> type ) ; hid_dbg ( hdev , " \n " , report -> maxfield ) ; if ( report -> type != HID_INPUT_REPORT ) return 1 ; ptr = raw_data ; ptr ++ ; spin_lock_irqsave ( & pdata -> lock , flags ) ; for ( i = 0 ; i < report -> maxfield ; ++ i ) { hid_dbg ( hdev , " \n " , i , report -> field [ i ] -> usage -> collection_index , report -> field [ i ] -> usage -> hid , ( report -> field [ i ] -> report_size * report -> field [ i ] -> report_count ) / 8 ) ; sz = ( report -> field [ i ] -> report_size * report -> field [ i ] -> report_count ) / 8 ; collection = & hdev -> collection [ report -> field [ i ] -> usage -> collection_index ] ; hid_dbg ( hdev , " \n " , collection -> usage ) ; callback = sensor_hub_get_callback ( hdev , report -> field [ i ] -> physical , report -> field [ i ] -> usage [ 0 ] . collection_index , & hsdev , & priv ) ; if ( ! callback ) { ptr += sz ; continue ; } if ( hsdev -> pending . status && ( hsdev -> pending . attr_usage_id == report -> field [ i ] -> usage -> hid || hsdev -> pending . attr_usage_id == report -> field [ i ] -> logical ) ) { hid_dbg ( hdev , " \n " ) ; hsdev -> pending . raw_data = kmemdup ( ptr , sz , GFP_ATOMIC ) ; if ( hsdev -> pending . raw_data ) hsdev -> pending . raw_size = sz ; else hsdev -> pending . raw_size = 0 ; complete ( & hsdev -> pending . ready ) ; } if ( callback -> capture_sample ) { if ( report -> field [ i ] -> logical ) callback -> capture_sample ( hsdev , report -> field [ i ] -> logical , sz , ptr , callback -> pdev ) ; else callback -> capture_sample ( hsdev , report -> field [ i ] -> usage -> hid , sz , ptr , callback -> pdev ) ; } ptr += sz ; } if ( callback && collection && callback -> send_event ) callback -> send_event ( hsdev , collection -> usage , callback -> pdev ) ; spin_unlock_irqrestore ( & pdata -> lock , flags ) ; return 1 ; }
Handle raw report as sent by device
Handle raw report as sent by device
/* Skip report id */