Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp134186lqt; Thu, 18 Apr 2024 10:19:21 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXmkOUYsbeS2fX9o/84Ki6ebu5H+3EDIVSHAbigtqm2bPxPk99QLWOKN/8AEjS/L0QTe44RZt3+nv8ygmgy/BP1YkLyeDVLl1E/xZlVgw== X-Google-Smtp-Source: AGHT+IF7o+BtHilPj6IhMH1RDCFiPp8HD7g36Y5aNSDpnOrFORKjfxQuyzMKZMxvrqZTvEktD8v9 X-Received: by 2002:a05:622a:4cd:b0:436:866e:ed51 with SMTP id q13-20020a05622a04cd00b00436866eed51mr3479477qtx.55.1713460761046; Thu, 18 Apr 2024 10:19:21 -0700 (PDT) Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id 5-20020a05621420c500b0069627b86c69si2057190qve.292.2024.04.18.10.19.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Apr 2024 10:19:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-150561-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@redhat.com header.s=mimecast20190719 header.b=SxJqzSj7; arc=fail (body hash mismatch); spf=pass (google.com: domain of linux-kernel+bounces-150561-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-150561-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 4A7F51C218C0 for ; Thu, 18 Apr 2024 17:19:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BC330172BDD; Thu, 18 Apr 2024 17:19:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="SxJqzSj7" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6680A171E6C for ; Thu, 18 Apr 2024 17:19:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713460754; cv=none; b=YiAHSaTuXe577m2phv7kE1QsfXVN6A6FW/IbUa5Kf9V/bBk6SXgUzyXnLRgRKGf44Unla1HbkgOJhWEd0VMQ3jgPrEDcShfACCrSaukVNXGkJ+OSWFXiQOJjgfieFbKlkv5yz7PL12lh3TOpWkPck3HPoEz5/6VehcM2gQQlyfo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713460754; c=relaxed/simple; bh=z8deP5JiCX4tE0osRAabfU/ka6kCpJORJ3z3SrfiQSQ=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=AkLGpSr9eNpNgRCTPF0Gwmme2j7QP1Nakpzok6YLf94xC+GLHFF0Mmi5GC5mBkCx3RGFD0VU5XnIuyxQowRVk/iVgZK0GGBQWEPb63TQaiIzS8zb84o4m83zPOXPCRQJ31BWUtHIxnUurIzEQHqvQX22WV70WpiwLdDlG+M/6yI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=SxJqzSj7; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1713460752; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=u5bV22Y6v5pDARLpQxuhoUtFKqLzg5Cehfkskiq3Udg=; b=SxJqzSj7R9u0s2zf1ptS+nOKQ8jRCRjq5Km8Hf6YQNC5bCAt18v7TuPQBwGqA3vUkPMPfO 3f6pBiJguCc2kARezjcMDDjnocMbo61wnBfyVKwouRumIsK3cMSdllLRp1o/Rhi593kVa3 L5w0V73RbGMliDoknlDZAc3f6mh/B7Y= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-383-x1Y1IXb-OR6tsYYaZ5Y7KQ-1; Thu, 18 Apr 2024 13:19:11 -0400 X-MC-Unique: x1Y1IXb-OR6tsYYaZ5Y7KQ-1 Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-43689467973so16064231cf.1 for ; Thu, 18 Apr 2024 10:19:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713460750; x=1714065550; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=u5bV22Y6v5pDARLpQxuhoUtFKqLzg5Cehfkskiq3Udg=; b=Fhh6CwyQsE6qUEOAedKIkYUjKQObezcOip3oQNf1BnXsgdD3+5LhOD9DNM59xcODQq H2FVtTnzBHzyqlT6To6oA/9Av5GSLEgDp4e1T4jWquedUksize/5rIjLrrDidudePCtu rW2Y/MwFMe9flyobRZiqW2r41/mWP3Ilm8z2HDWEko1XOG/+v4nVBs/vQcN2b+onh8XJ s3z94SMDs5wF/22Hpcq4ed4w78SLnhv38MgkxDlSgiGrXaGW2yviDYgIc0onoxuUnuGr SY1iinvKlNwQvCYzDaqRfQidky4bCwAuoz1hZidF8JsGuJ4meVhEGizT8Lk7yGYjtSJy czIg== X-Forwarded-Encrypted: i=1; AJvYcCXqtyxrphMfaP8JqWF3Pkdqw/tWGS2vNDGDYb9IOo80f3ANqXHmZFqBezB2qSwxw3uaSrVmIxsAvoH+wi6f1d53FhjrNRO2vSzxTbzr X-Gm-Message-State: AOJu0Yx81xnR+rtlMmQH1vyylLDjJfprdBMRJGUX/EnsavzS8JHOlLC8 iaug/GymBzHbrVFA5HrKCMqYWg1SXAVQRHA98bjJ/D00reZ9/zGaAMH/O5OHP3yajqj7k2PiNp+ 1h72VdKQrxhFN/uu5+CB4YVGLDntjtqvsY3NqZHmkvBu8kB5KMPzF+bEztYP7MBd54WVmSA4/b+ /QySj3+nb0QIgTq4NwZmKDyN5PNbS6qBcFu0De X-Received: by 2002:a05:622a:f:b0:436:ba2a:4aef with SMTP id x15-20020a05622a000f00b00436ba2a4aefmr4004842qtw.52.1713460750349; Thu, 18 Apr 2024 10:19:10 -0700 (PDT) X-Received: by 2002:a05:622a:f:b0:436:ba2a:4aef with SMTP id x15-20020a05622a000f00b00436ba2a4aefmr4004823qtw.52.1713460750106; Thu, 18 Apr 2024 10:19:10 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240418131754.58217-3-wander@redhat.com> <9ff84256-c7d2-48e5-b06b-09a993db2c39@web.de> In-Reply-To: <9ff84256-c7d2-48e5-b06b-09a993db2c39@web.de> From: Wander Lairson Costa Date: Thu, 18 Apr 2024 14:18:59 -0300 Message-ID: Subject: Re: [PATCH 2/2] kunit: avoid memory leak on device register error To: Markus Elfring Cc: kunit-dev@googlegroups.com, linux-kselftest@vger.kernel.org, kernel-janitors@vger.kernel.org, Brendan Higgins , David Gow , Rae Moar , LKML Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Apr 18, 2024 at 12:24=E2=80=AFPM Markus Elfring wrote: > > > If the device register fails, free the allocated memory before > > returning. > > * I suggest to use the word =E2=80=9Cregistration=E2=80=9D (instead of = =E2=80=9Cregister=E2=80=9D) > in the commit message. > > * Would you like to add the tag =E2=80=9CFixes=E2=80=9D accordingly? > > > > +++ b/lib/kunit/device.c > > @@ -131,6 +131,7 @@ static struct kunit_device *kunit_device_register_i= nternal(struct kunit *test, > > err =3D device_register(&kunit_dev->dev); > > if (err) { > > put_device(&kunit_dev->dev); > > + kfree(kunit_dev); > > return ERR_PTR(err); > > } > > Common error handling code can be used instead > if an additional label would be applied for a corresponding jump target. > > How do you think about to increase the application of scope-based resourc= e management here? > I thought about that. But I think the code is simple enough (for now) to not require an exit label. > Regards, > Markus >