Received: by 2002:a05:6358:f14:b0:e5:3b68:ec04 with SMTP id b20csp5421392rwj; Wed, 21 Dec 2022 02:22:59 -0800 (PST) X-Google-Smtp-Source: AMrXdXvgdm0V7jJJOB32z4vekNfIhlNeLdWtoThjjYvvwgQIr5cC0gzqzTJCyKaTl46d/7pzd/c4 X-Received: by 2002:a17:90a:cb15:b0:221:6db8:320c with SMTP id z21-20020a17090acb1500b002216db8320cmr1576457pjt.23.1671618178864; Wed, 21 Dec 2022 02:22:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671618178; cv=none; d=google.com; s=arc-20160816; b=GLftoW0hQXz6Jhe6DMrfNpJZFTZLHNHTuSwB/kpQbreZxURWEOE/03PymTmpsUkQpa 7X56sN+gjY1lcUPrPaQjRYCmwPxkh3+lt6WGajNveAALKdL2h4cPt0LL4NhxvgNcgEyg GgKLGA6WWbZY6Zmv8oQ1+yl+Xmx5DvtpxCvxsp/oxyCmIwTWQB2r3xxROvcsG8F6z4tK Ipbl+88NWIMCcYcEBNuL04RrvV18XIHXEeu5+586TgO1O7uswmxcUiQC7bsrzoc+2gpb Ab7eGpDthoLwr0UDINblz/3VuxRzVBYBBZ6rTtVP4qICeaijs8G7yMGKamGUg8OmVx63 FmZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:to:content-language:subject:user-agent:mime-version:date :message-id:dkim-signature; bh=00Inf63iGaAsVhYSavXD2K2q3AWuG2Zj5gcQJk+z2i4=; b=cXIALhroAVItrme8BYdZj4YaiqpnO8DtaOJF2+LqxmR90WKxdcE/l5PmbRne2UbHwt O0OFrf1URcBatqWZi9iStDLj5FKo0f4FFfVljURN1eBvOHxIE+BWP54XVO5mYPJzap/C OXFlPQLvzIq7NrPYShxJqVQYpJ1UiTo/Ip9uRhBtmso0QtxWpSOIpsXtqZRNPvtyHaJq BKWkO0ALUGDtIAEe2TUuf5ksTkWPakqWUxTZ7tV1YClkfpqXhHCaxZp3J/TEOLxfMYDs 8r3lgNKty1anautVV27tphCMHbd/SXPYcr1BvoPcflTRe36jHhpagA+X6TZAHRPH9N1o 0HdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qTLeLBAc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f2-20020a17090aa78200b00219ff54ef23si1300262pjq.107.2022.12.21.02.22.50; Wed, 21 Dec 2022 02:22:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qTLeLBAc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234609AbiLUJpm (ORCPT + 69 others); Wed, 21 Dec 2022 04:45:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52418 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234614AbiLUJpe (ORCPT ); Wed, 21 Dec 2022 04:45:34 -0500 Received: from mail-lf1-x131.google.com (mail-lf1-x131.google.com [IPv6:2a00:1450:4864:20::131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 664BB21E33 for ; Wed, 21 Dec 2022 01:45:32 -0800 (PST) Received: by mail-lf1-x131.google.com with SMTP id bf43so22657249lfb.6 for ; Wed, 21 Dec 2022 01:45:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=00Inf63iGaAsVhYSavXD2K2q3AWuG2Zj5gcQJk+z2i4=; b=qTLeLBAcwolPiW0pMxHIgX/+j4GMOVsFLzYLYdKKubLh89RJVmTl1YEtvk8+IFqm+w uNFT8wrUcNT8ohDTMB/IoJZ1hAaUblf1Nwjvo6+CyArxUKbFDKAQcXi6G6rUqj7Veyv1 p4N/MDL+UvnFv5bxX2/iVT6se0BPJ8le7aDutnLJsatj9/k2lnhCle43ZyP1GB0LtzS4 NQF+Mcaxli1Z8EjkFJ6GF+jxWg+der6A3j1ORGy19Nr6XiRayjHML2EIILLhcB4MTd/D zsKx2sC09KszSvML1G6T6L97u9c185I0x+83Z7l5Kq8wOBjZ+sF0lYzyRaSZViSme3Yd ikMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=00Inf63iGaAsVhYSavXD2K2q3AWuG2Zj5gcQJk+z2i4=; b=7J/xgD1wnOQMvenUnSpL6IYN3cHIIcP6CSu/9O8giOK90DpnBArWuDx16Z0nGpKOMT +Qu6jdmKd7DtOhPt3T62Q0KzRlOGn7BESJbUWs4uC1Pz+MhDQj3uOqTePkYRb//mAgzh DbDwGKxzCi4YqpSZEhHupXCw2YM5gl2KUSo5tZJC0Gf+L8Ofzdz8LOXUfnl8934shdk0 d0OjP0mGL20iToWCHkUg3SZOhan//DUmENo3CRZvQ1R3IQKiW7zwCbYqhon84zNkYo1c LA4PeuIH3sEnWruT3uH6iJqZIHcaKh44vNC20vap3pCnz25uAkkfyvmVpTjtxFEuX23F xtLQ== X-Gm-Message-State: AFqh2kpC35ZhitCLYLOT8x9jeYnPZ9v0IDUmAySu8L76llbECUJ9XgKy Wbc8xU4ACnVopNWoJ5LBQ+B5WA== X-Received: by 2002:a05:6512:6d0:b0:4b5:d:efb2 with SMTP id u16-20020a05651206d000b004b5000defb2mr410566lff.14.1671615930786; Wed, 21 Dec 2022 01:45:30 -0800 (PST) Received: from [192.168.0.20] (088156142067.dynamic-2-waw-k-3-2-0.vectranet.pl. [88.156.142.67]) by smtp.gmail.com with ESMTPSA id y4-20020a197504000000b0049c29389b98sm1777424lfe.151.2022.12.21.01.45.29 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 21 Dec 2022 01:45:30 -0800 (PST) Message-ID: <0f1d8479-657a-acb2-4a8d-69ae5a451a63@linaro.org> Date: Wed, 21 Dec 2022 10:45:29 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.0 Subject: Re: [PATCH] nfc: Fix potential resource leaks Content-Language: en-US To: Miaoqian Lin , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Samuel Ortiz , Christophe Ricard , netdev@vger.kernel.org, linux-kernel@vger.kernel.org References: <20221220134623.2084443-1-linmq006@gmail.com> From: Krzysztof Kozlowski In-Reply-To: <20221220134623.2084443-1-linmq006@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 20/12/2022 14:46, Miaoqian Lin wrote: > nfc_get_device() take reference for the device, add missing > nfc_put_device() to release it when not need anymore. > Also fix the style warnning by use error EOPNOTSUPP instead of > ENOTSUPP. > > Fixes: 5ce3f32b5264 ("NFC: netlink: SE API implementation") > Fixes: 29e76924cf08 ("nfc: netlink: Add capability to reply to vendor_cmd with data") > Signed-off-by: Miaoqian Lin > --- > net/nfc/netlink.c | 51 ++++++++++++++++++++++++++++++++++------------- > 1 file changed, 37 insertions(+), 14 deletions(-) > > diff --git a/net/nfc/netlink.c b/net/nfc/netlink.c > index 9d91087b9399..d081beaf4828 100644 > --- a/net/nfc/netlink.c > +++ b/net/nfc/netlink.c > @@ -1497,6 +1497,7 @@ static int nfc_genl_se_io(struct sk_buff *skb, struct genl_info *info) > u32 dev_idx, se_idx; > u8 *apdu; > size_t apdu_len; > + int error; Let's don't introduce the third or fourth style. Existing code calls it "rc". > > if (!info->attrs[NFC_ATTR_DEVICE_INDEX] || > !info->attrs[NFC_ATTR_SE_INDEX] || > @@ -1510,25 +1511,37 @@ static int nfc_genl_se_io(struct sk_buff *skb, struct genl_info *info) > if (!dev) > return -ENODEV; > > - if (!dev->ops || !dev->ops->se_io) > - return -ENOTSUPP; > + if (!dev->ops || !dev->ops->se_io) { > + error = -EOPNOTSUPP; > + goto put_dev; > + } > > apdu_len = nla_len(info->attrs[NFC_ATTR_SE_APDU]); > - if (apdu_len == 0) > - return -EINVAL; > + if (apdu_len == 0) { > + error = -EINVAL; > + goto put_dev; > + } > > apdu = nla_data(info->attrs[NFC_ATTR_SE_APDU]); > - if (!apdu) > - return -EINVAL; > + if (!apdu) { > + error = -EINVAL; > + goto put_dev; > + } > > ctx = kzalloc(sizeof(struct se_io_ctx), GFP_KERNEL); > - if (!ctx) > - return -ENOMEM; > + if (!ctx) { > + error = -ENOMEM; > + goto put_dev; > + } > > ctx->dev_idx = dev_idx; > ctx->se_idx = se_idx; > > - return nfc_se_io(dev, se_idx, apdu, apdu_len, se_io_cb, ctx); > + error = nfc_se_io(dev, se_idx, apdu, apdu_len, se_io_cb, ctx); > + > +put_dev: > + nfc_put_device(dev); > + return error; > } > > static int nfc_genl_vendor_cmd(struct sk_buff *skb, > @@ -1551,14 +1564,20 @@ static int nfc_genl_vendor_cmd(struct sk_buff *skb, > subcmd = nla_get_u32(info->attrs[NFC_ATTR_VENDOR_SUBCMD]); > > dev = nfc_get_device(dev_idx); > - if (!dev || !dev->vendor_cmds || !dev->n_vendor_cmds) > + if (!dev) > return -ENODEV; Blank line > + if (!dev->vendor_cmds || !dev->n_vendor_cmds) { > + err = -ENODEV; > + goto put_dev; > + } > > if (info->attrs[NFC_ATTR_VENDOR_DATA]) { > data = nla_data(info->attrs[NFC_ATTR_VENDOR_DATA]); > data_len = nla_len(info->attrs[NFC_ATTR_VENDOR_DATA]); > - if (data_len == 0) > - return -EINVAL; > + if (data_len == 0) { > + err = -EINVAL; > + goto put_dev; > + } > } else { > data = NULL; > data_len = 0; > @@ -1573,10 +1592,14 @@ static int nfc_genl_vendor_cmd(struct sk_buff *skb, > dev->cur_cmd_info = info; > err = cmd->doit(dev, data, data_len); > dev->cur_cmd_info = NULL; > - return err; > + goto put_dev; > } > > - return -EOPNOTSUPP; > + err = -EOPNOTSUPP; > + > +put_dev: > + nfc_put_device(dev); > + return err; > } > > /* message building helper */ Best regards, Krzysztof