From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 292C2C25B08 for ; Fri, 5 Aug 2022 14:02:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240661AbiHEOCf (ORCPT ); Fri, 5 Aug 2022 10:02:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233418AbiHEOCc (ORCPT ); Fri, 5 Aug 2022 10:02:32 -0400 Received: from mail-qv1-xf34.google.com (mail-qv1-xf34.google.com [IPv6:2607:f8b0:4864:20::f34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 642621EAE3 for ; Fri, 5 Aug 2022 07:02:31 -0700 (PDT) Received: by mail-qv1-xf34.google.com with SMTP id i4so1796554qvv.7 for ; Fri, 05 Aug 2022 07:02:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc; bh=PFnHGBECzH93Bid1BcKUvOoiH9cK0ZrzfdY2sz0NSVc=; b=SRV9cO/VpygIMukey2dbFcaehhdni/hFVT+6U6EAJ6zXrCXpY2RjCF1G/gbePvpWcf hRvZC4efs3/TwwkyqqD8+cVnHKa6n+elQw/9p+mZf5Nkn23Vk69lZZrZcW5LJP1gLTCZ h4rMejPk9KeoJCUBHKoeLMgmmqjVKThJOIu/l9OgGpKINhozfZt4k3EKL6Lq8tFzrfmQ y8oRsvq7yydRdFviNXUw0fvB6t4XjIIggtsjdsidIa7fxkOCE95zFKQQ7v3evzZlz5em t+Xa4AqaGoDfXKnoaFkFjEbiGTj6h49hkMiRcK75DSTzvVROSWEJ53JLZPNFdVxD+IoY BOxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc; bh=PFnHGBECzH93Bid1BcKUvOoiH9cK0ZrzfdY2sz0NSVc=; b=FCUeuRGj9O5TnRTHUbn4UoeSbrcwHUfrTwFIIiyswid9bu3g2FQxkJggnroceAuYiv 7PZBTVaP09lHgG5cFgZj3dVB1BGTmRS+BSNMgzFeLkl+MES2j8bg7FNfxABe9qns54sT MvDKWDCFX8AEo1r4KUYvFnggKhn5hYKCoHXTQINnZy+OmVvHMaYG+4mEqsFgXiV/QUSg gZAps1beBRqEIUirj7yi5juKKkLj2yKaUeYPDd16J7I9vtUp73mymhyqZLKKYnFEEA5a +eDvu+0U7MBCkTCUWN7bDSqHxhBuCFSUlml53GI7d+nWd5FowIWpMgHM77Xy3g3mpFGH ypPA== X-Gm-Message-State: ACgBeo1ZMBqoLpyFb3kE4jPlNqurxwdQE0ToGjlVaEEQ1oMh+1KeR4L9 wlDa6R8bShDAei9AH4XYM+dsfw== X-Google-Smtp-Source: AA6agR6VQghOT7mgljopZ7UoOiCJqL3A9+aHgoiOMcoOCLa1g0FsLknUdJd1iJM0lc0D33gmfs5nZw== X-Received: by 2002:a0c:9d01:0:b0:474:4c67:8f96 with SMTP id m1-20020a0c9d01000000b004744c678f96mr5686609qvf.32.1659708150506; Fri, 05 Aug 2022 07:02:30 -0700 (PDT) Received: from ziepe.ca (hlfxns017vw-142-162-113-129.dhcp-dynamic.fibreop.ns.bellaliant.net. [142.162.113.129]) by smtp.gmail.com with ESMTPSA id i14-20020a05620a248e00b006b57b63a8ddsm2974037qkn.122.2022.08.05.07.02.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Aug 2022 07:02:29 -0700 (PDT) Received: from jgg by wakko with local (Exim 4.95) (envelope-from ) id 1oJxuG-004Tmc-Tj; Fri, 05 Aug 2022 11:02:28 -0300 Date: Fri, 5 Aug 2022 11:02:28 -0300 From: Jason Gunthorpe To: Bo Liu Cc: bvanassche@acm.org, leon@kernel.org, linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] RDMA/srp: Check dev_set_name() return value Message-ID: References: <20220805053434.3944-1-liubo03@inspur.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220805053434.3944-1-liubo03@inspur.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Aug 05, 2022 at 01:34:34AM -0400, Bo Liu wrote: > It's possible that dev_set_name() returns -ENOMEM, catch and handle this. > > Signed-off-by: Bo Liu > --- > drivers/infiniband/ulp/srp/ib_srp.c | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) Ah, while you are here can you fix this: > if (device_register(&host->dev)) > goto free_host; [..] > free_host: > kfree(host); That isn't allowed, you have to do put_device(): /** * device_register - register a device with the system. * @dev: pointer to the device structure * * This happens in two clean steps - initialize the device * and add it to the system. The two steps can be called * separately, but this is the easiest and most common. * I.e. you should only call the two helpers separately if * have a clearly defined need to use and refcount the device * before it is added to the hierarchy. * * For more information, see the kerneldoc for device_initialize() * and device_add(). * * NOTE: _Never_ directly free @dev after calling this function, even * if it returned an error! Always use put_device() to give up the * reference initialized in this function instead. */ int device_register(struct device *dev) Everyone get this wrong, it is why I think device_register is a terrible interface. Write it as device_initialize()/device_add() as seperate steps and never call kfree(). Jason