From patchwork Mon Jul 4 11:14:45 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 71351 Delivered-To: patch@linaro.org Received: by 10.140.28.4 with SMTP id 4csp1498971qgy; Mon, 4 Jul 2016 04:14:52 -0700 (PDT) X-Received: by 10.66.149.66 with SMTP id ty2mr21438468pab.153.1467630892424; Mon, 04 Jul 2016 04:14:52 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i79si3758003pfk.2.2016.07.04.04.14.52; Mon, 04 Jul 2016 04:14:52 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-gpio-owner@vger.kernel.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753023AbcGDLOv (ORCPT + 4 others); Mon, 4 Jul 2016 07:14:51 -0400 Received: from mail-lf0-f49.google.com ([209.85.215.49]:34559 "EHLO mail-lf0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752444AbcGDLOv (ORCPT ); Mon, 4 Jul 2016 07:14:51 -0400 Received: by mail-lf0-f49.google.com with SMTP id h129so115190090lfh.1 for ; Mon, 04 Jul 2016 04:14:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=bQ70BCX+Eqb9/l+yEywKrgLMFfd1aQSjI/LuCAjo4lM=; b=gyevDY614rbHVAB075adwCnuucOvFEUYf3hH9Mj5BGoyp6MyS+HEl+fu5BGvYl0J/X rMpjySZsyNTT2eOCQ7qnH1Sf04b/G6RxqUM07wsOVDaUysGsRP/dYIrhETeQVZFyco86 TRjM9iJ/D7fTVY2lV7URZjISzUrGBrL8oJcZg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=bQ70BCX+Eqb9/l+yEywKrgLMFfd1aQSjI/LuCAjo4lM=; b=kxnxhioi7xwN6Cb/6BEJwAir/0UTs/90WouOjE7RAg6J7cQPiPYTYqHSV6yTM7ewUi rfg4WXVAOK1RyU/kJtVBAWEqbVsoiyC8hqVL9IKD828pSlIx3zVZuJHKHs8W3wJCXWdi NpWZqstVt8oe5wM6Zw0KFjH7txtw0aQ/TMkYZLtHcdqYwTYUmHGa8S+ZIGyDXI1AJmmp Zkgfva2crNPl+67evWKSH8m2lqLXfQCGSXZBqoyVYgc69SCw0pW5qBieGh6k2PXjr4ND 60LYBqwp2NxjS39l2h/SZeGORMt2nTQUWHeVd/C7e2dgkH2fVcNwqjsZibnNU60G5k6F 8pPA== X-Gm-Message-State: ALyK8tIT57JKow2r1gMHCxslCw4YvutTOw82SiEtaVntErXpjc7m2Ks9XhMr1rrfFQ3cZC5z X-Received: by 10.25.15.213 with SMTP id 82mr2204325lfp.126.1467630889303; Mon, 04 Jul 2016 04:14:49 -0700 (PDT) Received: from localhost.localdomain ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id 12sm4593733ljf.17.2016.07.04.04.14.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Jul 2016 04:14:48 -0700 (PDT) From: Linus Walleij To: linux-gpio@vger.kernel.org, Alexandre Courbot Cc: Linus Walleij Subject: [PATCH] gpio: free handles in fringe cases Date: Mon, 4 Jul 2016 13:14:45 +0200 Message-Id: <1467630885-3042-1-git-send-email-linus.walleij@linaro.org> X-Mailer: git-send-email 2.4.11 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org If we fail when copying the ioctl() struct to userspace we still need to clean up the cruft otherwise left behind or it will stay around until the issuing process terminates the file handle. Reported-by: Alexander Stein Signed-off-by: Linus Walleij --- drivers/gpio/gpiolib.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) -- 2.4.11 -- To unsubscribe from this list: send the line "unsubscribe linux-gpio" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index b195ec406ff4..69efe278f74d 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -488,8 +488,10 @@ static int linehandle_create(struct gpio_device *gdev, void __user *ip) } handlereq.fd = fd; - if (copy_to_user(ip, &handlereq, sizeof(handlereq))) - return -EFAULT; + if (copy_to_user(ip, &handlereq, sizeof(handlereq))) { + ret = -EFAULT; + goto out_free_descs; + } dev_dbg(&gdev->dev, "registered chardev handle for %d lines\n", lh->numdescs); @@ -784,8 +786,10 @@ static int lineevent_create(struct gpio_device *gdev, void __user *ip) } eventreq.fd = fd; - if (copy_to_user(ip, &eventreq, sizeof(eventreq))) - return -EFAULT; + if (copy_to_user(ip, &eventreq, sizeof(eventreq))) { + ret = -EFAULT; + goto out_free_irq; + } return 0;