Skip to contentSkip to conversation

intel_punit_ipc: add NULL check for input parameters

PATCH Applied Qipeng Zha 4 participants 6 messages Jan 8, 2016 – Jan 14, 2016 x86 platform drivers

lore
Share & tools
lore

Qipeng Zha

author
#0 lore raw

PATCH 1/1 intel_punit_ipc: add NULL check for input parameters

intel_punit_ipc_command() maybe called when in or out data pointers are NULL.

---
 drivers/platform/x86/intel_punit_ipc.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)
drivers/platform/x86/intel_punit_ipc.c +10 -6
index 16685bc..bd87540 100644
@@ -187,10 +187,12 @@ int intel_punit_ipc_command(u32 cmd, u32 para1, u32 para2, u32 *in, u32 *out)
 
 	reinit_completion(&ipcdev->cmd_complete);
 	type = (cmd & IPC_PUNIT_CMD_TYPE_MASK) >> IPC_TYPE_OFFSET;
-	ipc_write_data_low(ipcdev, type, *in);
 
-	if (type == GTDRIVER_IPC || type == ISPDRIVER_IPC)
-		ipc_write_data_high(ipcdev, type, *++in);
+	if (in) {
+		ipc_write_data_low(ipcdev, type, *in);
+		if (type == GTDRIVER_IPC || type == ISPDRIVER_IPC)
+			ipc_write_data_high(ipcdev, type, *++in);
+	}
 
 	val = cmd & ~IPC_PUNIT_CMD_TYPE_MASK;
 	val |= CMD_RUN | para2 << CMD_PARA2_SHIFT | para1 << CMD_PARA1_SHIFT;
@@ -199,10 +201,12 @@ int intel_punit_ipc_command(u32 cmd, u32 para1, u32 para2, u32 *in, u32 *out)
 	ret = intel_punit_ipc_check_status(ipcdev, type);
 	if (ret)
 		goto out;
-	*out = ipc_read_data_low(ipcdev, type);
 
-	if (type == GTDRIVER_IPC || type == ISPDRIVER_IPC)
-		*++out = ipc_read_data_high(ipcdev, type);
+	if (out) {
+		*out = ipc_read_data_low(ipcdev, type);
+		if (type == GTDRIVER_IPC || type == ISPDRIVER_IPC)
+			*++out = ipc_read_data_high(ipcdev, type);
+	}
 
 out:
 	mutex_unlock(&ipcdev->lock);
Signature · 1 line
1.8.3.2
#1 lore raw
Quoted 2 lines · On Fri, 8 Jan 2016 18:32:27 +0800 Qipeng Zha <[email protected]> wrote:

intel_punit_ipc_command() maybe called when in or out data pointers are NULL.

In which case what happens: the command is not issued but there seems to be no way for the caller to discover this, and nohing is logged.

Alan

#2 lore raw
Quoted 11 lines · One Thousand Gnomes
Quoted 2 lines · On Fri, 8 Jan 2016 18:32:27 +0800 Qipeng Zha <[email protected]> wrote:

intel_punit_ipc_command() maybe called when in or out data pointers are NULL.

In which case what happens: the command is not issued but there seems to be no way for the caller to discover this, and nohing is logged.

Alan

These functinos are not void, it seems an errcode or a message is in order.

Also, the commit message needs to document in what scenario intel_punit_ipc_command() may be called with null pointers - and why we consider that to be OK.

Signature · 2 lines
Darren Hart
Intel Open Source Technology Center
#3 lore raw
Quoted 22 lines

-----Original Message-----
From: [email protected] [mailto:platform-driver- [email protected]] On Behalf Of Darren Hart
Sent: Monday, January 11, 2016 11:22 PM
To: One Thousand Gnomes <[email protected]>
Cc: Zha, Qipeng <[email protected]>; platform-driver- [email protected]; [email protected]; Chakravarty, Souvik K <[email protected]>
Subject: Re: [PATCH] intel_punit_ipc: add NULL check for input parameters

Quoted 9 lines · One Thousand Gnomes
Quoted 2 lines · On Fri, 8 Jan 2016 18:32:27 +0800 Qipeng Zha <[email protected]> wrote:

intel_punit_ipc_command() maybe called when in or out data pointers are NULL.

In which case what happens: the command is not issued but there seems to be no way for the caller to discover this, and nohing is logged.

Quoted 8 lines
Quoted 2 lines

Alan

These functinos are not void, it seems an errcode or a message is in order.

Also, the commit message needs to document in what scenario intel_punit_ipc_command() may be called with null pointers - and why we consider that to be OK.

Darren,
In Punit IPC, all of the commands do not need an Input parameter; similarly all cmds do not need an output parameter(eg setting events). Telemetry uses all the flavors. (This fix is already there in our internal codebase for a long time, but somehow got missed during upstreaming). So this is not an error condition & the API needs to handle all cases properly.

Quoted 8 lines

--
Darren Hart
Intel Open Source Technology Center
--
To unsubscribe from this list: send the line "unsubscribe platform-driver-x86" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#4 lore raw
In reply to One Thousand Gnomes
Quoted 8 lines · One Thousand Gnomes
Quoted 2 lines · On Fri, 8 Jan 2016 18:32:27 +0800 Qipeng Zha <[email protected]> wrote:

intel_punit_ipc_command() maybe called when in or out data pointers are NULL.

In which case what happens: the command is not issued but there seems to be no way for the caller to discover this, and nohing is logged.

My reading of this is different.

A command receives a type and a val. It may or may not also require data in the "in" buffer, and the caller may or may not provide an out buffer.

The command is issued in any case.

I have merged this to avoid a crash, but we can certainly revisit this if I have missed something.

Signature · 2 lines
Darren Hart
Intel Open Source Technology Center