From patchwork Thu Apr 21 21:11:25 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jesper Juhl X-Patchwork-Id: 725751 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p3LLHsYU007308 for ; Thu, 21 Apr 2011 21:17:54 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754774Ab1DUVRg (ORCPT ); Thu, 21 Apr 2011 17:17:36 -0400 Received: from swampdragon.chaosbits.net ([90.184.90.115]:21795 "EHLO swampdragon.chaosbits.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754601Ab1DUVRf (ORCPT ); Thu, 21 Apr 2011 17:17:35 -0400 Received: by swampdragon.chaosbits.net (Postfix, from userid 1000) id 4389A9403D; Thu, 21 Apr 2011 23:11:25 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by swampdragon.chaosbits.net (Postfix) with ESMTP id 4161D9403B; Thu, 21 Apr 2011 23:11:25 +0200 (CEST) Date: Thu, 21 Apr 2011 23:11:25 +0200 (CEST) From: Jesper Juhl To: linux-media@vger.kernel.org cc: trivial@kernel.org, linux-kernel@vger.kernel.org, Mauro Carvalho Chehab , Joe Perches Subject: [PATCH][Trivial] Media, DVB, Siano, smsusb: Avoid static analysis report about 'use after free'. Message-ID: User-Agent: Alpine 2.00 (LNX 1167 2008-08-23) MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Thu, 21 Apr 2011 21:17:56 +0000 (UTC) In drivers/media/dvb/siano/smsusb.c we have this code: ... kfree(dev); sms_info("device %p destroyed", dev); ... at least one static analysis tool (Coverity Prevent) complains about this as a use-after-free bug. While it's true that we do use the pointer variable after freeing it, the only use is to print the value of the pointer, so there's not actually any problem here. But still, silencing the complaint is trivial by just moving the kfree() call below the sms_info(), so why not just do it?. It doesn't change the workings of the code in any way, but it makes the tool shut up. The patch below also removes a rather pointless blank line. Signed-off-by: Jesper Juhl --- smsusb.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/media/dvb/siano/smsusb.c b/drivers/media/dvb/siano/smsusb.c index 0b8da57..0c8164a 100644 --- a/drivers/media/dvb/siano/smsusb.c +++ b/drivers/media/dvb/siano/smsusb.c @@ -297,9 +297,8 @@ static void smsusb_term_device(struct usb_interface *intf) if (dev->coredev) smscore_unregister_device(dev->coredev); - kfree(dev); - sms_info("device %p destroyed", dev); + kfree(dev); } usb_set_intfdata(intf, NULL);