Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1547435pxb; Wed, 10 Feb 2021 10:49:07 -0800 (PST) X-Google-Smtp-Source: ABdhPJyJw+yMqMCNgSSLkej9QpPTDJ6E2E76Axg0zkh5DPPgDKus+JA2Szp/cYFGRzvmzvWmyPPY X-Received: by 2002:a17:906:c010:: with SMTP id e16mr4269975ejz.91.1612982946963; Wed, 10 Feb 2021 10:49:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612982946; cv=none; d=google.com; s=arc-20160816; b=qk7SYuHnimYk2//ccYi3JPNKYt5cKPvjov7GQd6Z8ZgidAbYLDFxmsl2S/q7gh8rL2 PVMAik1tEQaeinbozMI6/xebsAB6+ca0yy0azFA8zug6YehZIsAJpVK6nOck46mvdkyc 6znxCJNb93Ulfv/G/SvQQAdL9O9dOrb2GxIJv7+GXnXXXRXK0BOmye5JcI7eV+GR2Z7w 5uKonGSbhX2UYroI3ukcC6T7EDeOo0L1Ws12UH2DHKcxqVbVowyxc2WG7nbGPSJh1yus Uy2xSrBfDAiGy+0WKdv+imNfljlE4CP5HL25+0XUJauQ5WM6PtgBf/iIz23kDzrmGqcY LhIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version; bh=rxTS3+SRxomQSyYLoa8qx229pO2BpD0/9oWyAxDCXio=; b=Rt9lZ44zdyKJcJzbJY+U1F5+3EdmgxUUwHmzQvHulFWXKSlolUJrInUC1Py2l1R3/G cytRisjBMTKe0HyuwLQst0Xr8iY5dN7bBjy0FcYvkQ0NrCUsAqWrmmLkgoqDbu1cOi9U ZcQ67yHvmEMPPoKXouV343PkNlt5qq0uoBcvBQMCQQ3zNqlnZdQ9w9xCY0ZN3GmOWQV2 SmksUB1wW4RUOplUlQQk8lbr6yDqQq8ls4+wqeiSZhZaJlRYKSg9qn1QdC3HxHaqhgjc G2zFrNNj1Y8yDrzKPg3m7198rizhvsqY6GQiLtLRyZ/zCDqv6apYRKZGoYHJEP/RcFz4 LKQw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b22si1901610eds.547.2021.02.10.10.48.43; Wed, 10 Feb 2021 10:49:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234121AbhBJSr6 (ORCPT + 99 others); Wed, 10 Feb 2021 13:47:58 -0500 Received: from mail-ot1-f41.google.com ([209.85.210.41]:37651 "EHLO mail-ot1-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234296AbhBJSkI (ORCPT ); Wed, 10 Feb 2021 13:40:08 -0500 Received: by mail-ot1-f41.google.com with SMTP id a5so1594303otq.4; Wed, 10 Feb 2021 10:39:52 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=rxTS3+SRxomQSyYLoa8qx229pO2BpD0/9oWyAxDCXio=; b=kJycTYV4yEB65lu8kPvpI27iZ7XYAp8ZPPEi7EZ2bis+9oycFh8V+SG82H20XLYiIg 2vnUlPfsXVU5JM5rGAF44xnSUoOxUuvM2QPwMJ3ud7KbB0gp/cfor4EXEwcnj7r3TJPd Kq6wWeLhV67Trig5LAWlZFvYqAs3j0x22ijz+HXHuplaorn29fXnz1I2Lp93+oafItS8 kzyTs5yCuotW3oTAWMjOcLLrytUO232dA6X9zIC5/jGnALqDKMnRtC9FlQmLXpLasGyl Nvst3WEBxOVv/O+7jwJrNo/MUt6gItSdnx8+oRQ1USyel4/3boOLKUg7w5puD6/1VzB6 Ea9g== X-Gm-Message-State: AOAM533o2tIpM4vV/8LG6Y8n727XEGBRkqGZfR88ZYoCZEMw1YU8MMmu 0HiiDTjdpNDYH6sAjeVCtSCSf75VBO33MFjQXWcmDepk X-Received: by 2002:a05:6830:148d:: with SMTP id s13mr3142306otq.250.1612982367488; Wed, 10 Feb 2021 10:39:27 -0800 (PST) MIME-Version: 1.0 References: <20210210074946.155417-3-drew@beagleboard.org> <20210210182044.GY2696@kadam> In-Reply-To: <20210210182044.GY2696@kadam> From: Geert Uytterhoeven Date: Wed, 10 Feb 2021 19:39:16 +0100 Message-ID: Subject: Re: [PATCH v2 2/2] pinctrl: pinmux: Add pinmux-select debugfs file To: Dan Carpenter Cc: kbuild@lists.01.org, Drew Fustini , Linus Walleij , "open list:GPIO SUBSYSTEM" , Linux Kernel Mailing List , Tony Lindgren , Andy Shevchenko , Alexandre Belloni , Pantelis Antoniou , Jason Kridner , Robert Nelson , kbuild test robot , kbuild-all@lists.01.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Dan, On Wed, Feb 10, 2021 at 7:21 PM Dan Carpenter wrote: > 99b2f99aa41aa7 Drew Fustini 2021-02-09 694 buf = devm_kzalloc(pctldev->dev, PINMUX_MAX_NAME * 2, GFP_KERNEL); > 99b2f99aa41aa7 Drew Fustini 2021-02-09 695 if (!buf) > 99b2f99aa41aa7 Drew Fustini 2021-02-09 696 return -ENOMEM; > 99b2f99aa41aa7 Drew Fustini 2021-02-09 697 > 99b2f99aa41aa7 Drew Fustini 2021-02-09 698 fname = devm_kzalloc(pctldev->dev, PINMUX_MAX_NAME, GFP_KERNEL); > 99b2f99aa41aa7 Drew Fustini 2021-02-09 699 if (!fname) { > 99b2f99aa41aa7 Drew Fustini 2021-02-09 700 ret = -ENOMEM; > 99b2f99aa41aa7 Drew Fustini 2021-02-09 701 goto free_buf; > > The gotos are out of order. They should be in mirror/reverse order of > the allocations: > > free_gmane: > devm_kfree(pctldev->dev, gname); > free_fname: > devm_kfree(pctldev->dev, fname); > free_buf: > devm_kfree(pctldev->dev, buf); > > But also why do we need to use devm_kfree() at all? I thought the whole > point of devm_ functions was that they are garbage collected > automatically for you. Can we not just delete all error handling and > return -ENOMEM here? No, because the lifetime of the objects allocated here does not match the lifetime of dev. If they're not freed here, they will only be freed when the device is unbound. As the user can access the sysfs files at will, he can OOM the system. Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds