Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp538269rwe; Wed, 24 Aug 2022 05:25:12 -0700 (PDT) X-Google-Smtp-Source: AA6agR74DrnpeUfsMnPJ8LbNqFm38l4mX+ZwNnFS0tYmCF9rUnCp4vTlcq2SAWaoriIDsKHq0EkD X-Received: by 2002:a63:8a4b:0:b0:42a:5144:a44 with SMTP id y72-20020a638a4b000000b0042a51440a44mr18546011pgd.164.1661343912599; Wed, 24 Aug 2022 05:25:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661343912; cv=none; d=google.com; s=arc-20160816; b=JHCEqFoWVieGso0st77jdnXdLHAkvfjM/ZhdP0dY3Dy/9mmBWSVsB/VU6hsawgbkRU 37cgKEJy5nGTFpJtWwaH7+6mSS8v0WMscT0bb67EgTzvMU447uNeDwNAjbkbL0vWrEBG 9JEfhjRt3hri+keSeGQAVwHipqt5adFGQpCRhHJjDj/GH6EsGzToMXKVa+9G6y6QDcDg PMaxQrkbCkSuuZMxfpmpWgnWI+ESM5KN5G3bl3opTxa4oxjJ8rvuBQ8+LAJYQa2t6mJF ub+Onm153GyIuEsnHsSv4W7Y+ZGklPdQxDhvNxuq0UQydwQsi+yd0RLWQeQ5vQDJAQ9B 9IYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=2InmYYtGnTAoAEmL72HK3l4kFvHVYlOzzNylPfUjrzc=; b=rNEkRB02NvG1TptOhNAJG25Uqbgzgw8pEn3rHCW83jLpFAtpbSFKuQ1dveXgCLceP2 AgJNc6lFfu++7GDK1XuUFy0cUELSVnzf7RcH2ExHDPvh8TAo8ql5NKZEsITLIRGhP5PF 4C0aq5+qrTyQVEbSEcQ5cXAuPxTsfKJ8So5h/mcEeBEsEUDZFjOMNeqfhIOdL/Bw6LTC 1nJiKdSGZpCql9kZFafrBpzTPtc/RvYVd04k8FZ5jiUdVsSLbVwg8f1fVvUW3CEjk97+ 06yPf2UPCn7J0eK6PJJTr8P2T+3OMfNontP6RWgVQ1vHlYsMb2Nwz1IRBfv+GF/2c/WT YjMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=h0f2U2vX; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g12-20020a056a001a0c00b0051964d16f32si17729799pfv.180.2022.08.24.05.24.59; Wed, 24 Aug 2022 05:25:12 -0700 (PDT) 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=@kernel.org header.s=k20201202 header.b=h0f2U2vX; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236884AbiHXLve (ORCPT + 99 others); Wed, 24 Aug 2022 07:51:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40344 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236272AbiHXLvc (ORCPT ); Wed, 24 Aug 2022 07:51:32 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65CA882D17; Wed, 24 Aug 2022 04:51:31 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id F0C8161965; Wed, 24 Aug 2022 11:51:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D4146C433D7; Wed, 24 Aug 2022 11:51:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1661341890; bh=MQHLAPHxwZoEhShjrCExL3cR38x99rl36T1mPKu0zhU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=h0f2U2vXy/wN1zi0LZtjUj3FFYhDdW9gLLo3g1UcG43kc12LsZq9uwOL6O5fOdjPI wkSaQrnmRwKbbqgraDjzpPnUrlbc/MUlsD1VSYSrFtjAynUSw0gcitLC0SQZETzIKy d/jvdT0EDTDLEVvhGr+h0UNVGquXdBz3BOzxZcLapK2ckEXZ6B28Z6GhkCaAgU01G5 r15/p1wHQ94rr7J+xetUmCkxwwNfmU95trB8+pih/YaKboNjrA3r8qajm5JiosmZAS mkrLPeazuAFwgvEo3x4s+MoJG8eYe+CZdLQOEiwCBDokgZr28uLF+aW5bBvKJ/5frl RMiLv7uB/9mSg== Date: Wed, 24 Aug 2022 14:51:26 +0300 From: Leon Romanovsky To: Niels Dossche Cc: cgel.zte@gmail.com, dennis.dalessandro@cornelisnetworks.com, jgg@ziepe.ca, linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org, Minghao Chi , Zeal Robot Subject: Re: [PATCH] infiniband: remove unnecessary null check Message-ID: References: <20220824080503.221680-1-chi.minghao@zte.com.cn> <1ce29a1e-2db7-2953-b71e-c0408559ecff@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1ce29a1e-2db7-2953-b71e-c0408559ecff@gmail.com> X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,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 On Wed, Aug 24, 2022 at 10:15:56AM +0200, Niels Dossche wrote: > On 8/24/22 10:05, cgel.zte@gmail.com wrote: > > From: Minghao Chi > > > > container_of is never null, so this null check is > > unnecessary. > > > > Reported-by: Zeal Robot > > Signed-off-by: Minghao Chi > > --- > > drivers/infiniband/sw/rdmavt/vt.c | 2 -- > > 1 file changed, 2 deletions(-) > > > > diff --git a/drivers/infiniband/sw/rdmavt/vt.c b/drivers/infiniband/sw/rdmavt/vt.c > > index 59481ae39505..b2d83b4958fc 100644 > > --- a/drivers/infiniband/sw/rdmavt/vt.c > > +++ b/drivers/infiniband/sw/rdmavt/vt.c > > @@ -50,8 +50,6 @@ struct rvt_dev_info *rvt_alloc_device(size_t size, int nports) > > struct rvt_dev_info *rdi; > > > > rdi = container_of(_ib_alloc_device(size), struct rvt_dev_info, ibdev); > > - if (!rdi) > > - return rdi; > > > > rdi->ports = kcalloc(nports, sizeof(*rdi->ports), GFP_KERNEL); > > if (!rdi->ports) > > I believe this patch is incorrect because "_ib_alloc_device" may return a null pointer. > Note that the first member of "rvt_dev_info" is "ib_device", so the check on container_of effectively checks if the allocation failed, which is necessary to check. You are absolutely right, this container_of() and check later are done on purpose. It is open-coded variant of ib_alloc_device(...) macro. Thanks