Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp3809217pxm; Tue, 1 Mar 2022 05:57:28 -0800 (PST) X-Google-Smtp-Source: ABdhPJz2srOUDZKlkzmI8vg5nEPSSGZOZxjZoTajjgfN3CQRyAw7y49GdTYEGW/Ghcfy7YSWKFi8 X-Received: by 2002:a17:906:2991:b0:6cf:6b24:e92f with SMTP id x17-20020a170906299100b006cf6b24e92fmr18748556eje.748.1646143048560; Tue, 01 Mar 2022 05:57:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646143048; cv=none; d=google.com; s=arc-20160816; b=XVPa68eOnoHD9SJeuhyYEovHnFgx1ardIrLdgRZELt5wtu3a31Ro17EXyMqMcQ0Dk+ DuZmpGSEBmHhKEjlmw9EfYrg7dQQYvXav0YCG5FC118UPsrjzlp7rfjzNqkvq/ns1fcS 2eiXU1M+otbjAyrAc10hYLJlANCZllbRjT+0Bxlk5yu0S88HW+GAqwg0UYvsaGlGcPDR Bpzp/WMTOFKETIRXfObWMIiaA39bbh8LD2muXu+kRAy31MschwLVIEPwNj0b0oxZQNTh 2yaz4jMZcUMUH3QYrZTgTsrCpomh+Cq66eCAo6C44cI2fZqnCyQ3Iz3GJ4BheV9qoGAp UwdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:dkim-signature; bh=3gAUw2bljeQgo+EIP3uDFWmam1knQZu7pffpGmaV4fk=; b=H2IH7c4vd/uHiB2lAAnFyJgub4ag53976KFKRH/E+nEBwOces22onuuyf5oLsPcgv+ hGegAe6TTlFELC7xnTirsTToCL0UE/S7vOwxdgMn7CZtQAvPPPnPpNBohaGW6l9vMWo7 sz0foTZ7ef36FeeoZ02ldjkvk5Jo59NSL9ZYgkSmhYSIljYI8URhFFYvpnIwGPT+65Na lCQH0bdc3+cPANh+vMs5/PwiQ8b2Glb0V8UegRWgXZPx3+P6oia+6ihs0tcQJLpZfYdG KdWsxnpfLXHL0v5VEV76OYvZlUda3yfdPU6GypKrsAZZlS5Mbw0Q2Ugg37uDThsjIcSV u0/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ellerman.id.au header.s=201909 header.b=dlVJsWZX; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s8-20020a508dc8000000b00412d20d9ff4si8784520edh.183.2022.03.01.05.57.03; Tue, 01 Mar 2022 05:57:28 -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=@ellerman.id.au header.s=201909 header.b=dlVJsWZX; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234863AbiCAM4X (ORCPT + 99 others); Tue, 1 Mar 2022 07:56:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34234 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230415AbiCAM4W (ORCPT ); Tue, 1 Mar 2022 07:56:22 -0500 Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7CBF78A318 for ; Tue, 1 Mar 2022 04:55:40 -0800 (PST) Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 4K7HKk1xG8z4xPt; Tue, 1 Mar 2022 23:55:38 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ellerman.id.au; s=201909; t=1646139338; bh=3gAUw2bljeQgo+EIP3uDFWmam1knQZu7pffpGmaV4fk=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=dlVJsWZXk+G/5EIS6pOP76i9u12kyE3/AwRjYtkWQDUaSChKkxstgICysnR1WNgZi 7CrNqGb+0B5EdXQSh+3R7DzUA3c9CiOXS0Ozj5tDNG2V/e/ikkI83Ngdq/ndgw/TZQ 7yBJwtiN3X6oP638JzaoGKtuLi/MwoiZYogkr+9sLMKkiEL5waISY3OIbY6WdEX7QL YTgis/hp3vihz82rnv2XaKrdagoQDFgQbv3vmvkv33Ard89MNdONaFr9K/IeUu8cTf nrC6NDS5xQ1EPCapfFcHV6tZ0Zp/dsam/3TJ0jzg0BeBvZkoHuZ5gvEWWl0Wu83saW 04qgfukwQbWQQ== From: Michael Ellerman To: Hangyu Hua , benh@kernel.crashing.org, paulus@samba.org Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, Hangyu Hua Subject: Re: [PATCH] powerpc: kernel: fix a refcount leak in format_show() In-Reply-To: <20220228091103.39749-1-hbh25y@gmail.com> References: <20220228091103.39749-1-hbh25y@gmail.com> Date: Tue, 01 Mar 2022 23:55:35 +1100 Message-ID: <87o82pomrc.fsf@mpe.ellerman.id.au> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE 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 Hangyu Hua writes: > node needs to be dropped when of_property_read_string fails. So an earlier call > to of_node_put is required here. That's true but ... > diff --git a/arch/powerpc/kernel/secvar-sysfs.c b/arch/powerpc/kernel/secvar-sysfs.c > index a0a78aba2083..cd0fa7028d86 100644 > --- a/arch/powerpc/kernel/secvar-sysfs.c > +++ b/arch/powerpc/kernel/secvar-sysfs.c > @@ -30,13 +30,12 @@ static ssize_t format_show(struct kobject *kobj, struct kobj_attribute *attr, > return -ENODEV; There's also a reference leak there ^ So if you're going to touch this code I'd like you to fix both reference leaks in a single patch please. Having the error cases set rc and then goto "out" which does the of_node_put() is the obvious solution I think. cheers > rc = of_property_read_string(node, "format", &format); > + of_node_put(node); > if (rc) > return rc; > > rc = sprintf(buf, "%s\n", format); > > - of_node_put(node); > - > return rc; > } > > -- > 2.25.1