Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757706AbbEVPXO (ORCPT ); Fri, 22 May 2015 11:23:14 -0400 Received: from smtp89.iad3a.emailsrvr.com ([173.203.187.89]:48091 "EHLO smtp89.iad3a.emailsrvr.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757344AbbEVPVw (ORCPT ); Fri, 22 May 2015 11:21:52 -0400 X-Sender-Id: abbotti@mev.co.uk From: Ian Abbott To: Cc: Greg Kroah-Hartman , Ian Abbott , H Hartley Sweeten , Subject: [PATCH 1/4] staging: comedi: 8255: fix I/O region leak on failure Date: Fri, 22 May 2015 16:21:35 +0100 Message-Id: <1432308098-29247-2-git-send-email-abbotti@mev.co.uk> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1432308098-29247-1-git-send-email-abbotti@mev.co.uk> References: <1432308098-29247-1-git-send-email-abbotti@mev.co.uk> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1813 Lines: 48 The Comedi "8255" driver does not clean up properly on failure. It can leave requested I/O port regions unreleased. Specifically, the Comedi "attach" handler (`dev_8255_attach()`) requests a specified I/O port region before calling `subdev_8255_init()` to set up the subdevice. If that fails, the "attach" handler returns an error and the Comedi core will call the "detach" handler (`dev_8255_detach()`) to clean up. The "detach" handler is responsible for releasing the I/O port regions successfully requested by the "attach" handler. Unfortunately, it is unable to obtain the base address of the region if the call to `subdev_8255_init()` failed. Fix the I/O region leak by releasing the region in the "attach" handler directly if the call to `subdev_8255_init()` fails. Signed-off-by: Ian Abbott --- drivers/staging/comedi/drivers/8255.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/staging/comedi/drivers/8255.c b/drivers/staging/comedi/drivers/8255.c index ba89321..0fdf834 100644 --- a/drivers/staging/comedi/drivers/8255.c +++ b/drivers/staging/comedi/drivers/8255.c @@ -306,8 +306,15 @@ static int dev_8255_attach(struct comedi_device *dev, s->type = COMEDI_SUBD_UNUSED; } else { ret = subdev_8255_init(dev, s, NULL, iobase); - if (ret) + if (ret) { + /* + * Release the I/O port region here, as the + * "detach" handler cannot find it. + */ + release_region(iobase, I8255_SIZE); + s->type = COMEDI_SUBD_UNUSED; return ret; + } } } -- 2.1.4 -- 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/