Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756963AbbBEMTa (ORCPT ); Thu, 5 Feb 2015 07:19:30 -0500 Received: from userp1040.oracle.com ([156.151.31.81]:40690 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752441AbbBEMT2 (ORCPT ); Thu, 5 Feb 2015 07:19:28 -0500 Date: Thu, 5 Feb 2015 15:19:14 +0300 From: Dan Carpenter To: Rickard Strandqvist Cc: Sudip Mukherjee , "devel@driverdev.osuosl.org" , Greg Kroah-Hartman , Kiran Padwal , Linux Kernel Mailing List Subject: Re: [PATCH] staging: gdm724x: gdm_tty: Fix for possible null pointer dereference Message-ID: <20150205121913.GE5336@mwanda> References: <1422557170-3357-1-git-send-email-rickard_strandqvist@spectrumdigital.se> <20150202163633.GA30631@sudip-PC> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-Source-IP: acsinet21.oracle.com [141.146.126.237] Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1905 Lines: 48 On Wed, Feb 04, 2015 at 06:46:34PM +0100, Rickard Strandqvist wrote: > 2015-02-02 17:36 GMT+01:00 Sudip Mukherjee : > > On Thu, Jan 29, 2015 at 07:46:10PM +0100, Rickard Strandqvist wrote: > >> diff --git a/drivers/staging/gdm724x/gdm_tty.c b/drivers/staging/gdm724x/gdm_tty.c > >> index 001348c..66b356e 100644 > >> --- a/drivers/staging/gdm724x/gdm_tty.c > >> +++ b/drivers/staging/gdm724x/gdm_tty.c > >> @@ -145,7 +145,7 @@ static int gdm_tty_recv_complete(void *data, > >> struct gdm *gdm = tty_dev->gdm[index]; > >> > >> if (!GDM_TTY_READY(gdm)) { > >> - if (complete == RECV_PACKET_PROCESS_COMPLETE) > >> + if (gdm && complete == RECV_PACKET_PROCESS_COMPLETE) > > GDM_TTY_READY() is already checking for gdm, there is no chance that gdm can be null at this point. so this additional check is not required. > > > > regards > > sudip > >> gdm_tty_recv(gdm, gdm_tty_recv_complete); > >> return TO_HOST_PORT_CLOSE; > >> } > > Hi Sudip > > Yes, GDM_TTY_READY checks gdm, but this is a if(! ) > You're right. But, by that same logic, we should also test gdm->tty_dev. So it looks like this: if (!GDM_TTY_READY(gdm)) { if (gdm && gdm->tty_dev && complete == RECV_PACKET_PROCESS_COMPLETE) gdm_tty_recv(gdm, gdm_tty_recv_complete); return TO_HOST_PORT_CLOSE; } That is really sucky... Garbage code like this is why kernel style doesn't favour macros. We should just open code GDM_TTY_READY() and gdm_tty_recv() so that people can read the code. I wonder if "gdm->tty_dev" is the same as the "tty_dev" parameter? regards, dan carpenter -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/