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 29D1EC433FE for ; Tue, 17 May 2022 18:03:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351713AbiEQSDJ (ORCPT ); Tue, 17 May 2022 14:03:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38218 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345621AbiEQSDH (ORCPT ); Tue, 17 May 2022 14:03:07 -0400 Received: from mail-qk1-x731.google.com (mail-qk1-x731.google.com [IPv6:2607:f8b0:4864:20::731]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D8CA3FBC3 for ; Tue, 17 May 2022 11:03:06 -0700 (PDT) Received: by mail-qk1-x731.google.com with SMTP id 185so15147267qke.7 for ; Tue, 17 May 2022 11:03:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=qYLGulgiXtqkGHB5690TZrqi9P52kY4/ILEk7GNvo8I=; b=d1EWMzvycfAGBYsJZQZH5yrENWSi0Lz37ujcaPlZJ4unA4H0x3pCDDdIZeuaKcwI6N rCxeOBcZd2ndnT4BRF+FeOisiuQXpk0ExFqrIfVAqFKk1yxTNEHuHuZXSkKIfFvGqZX+ bFlI31Uf4DpfWyUopf5y37IaB+mI2+gBIuSMpW24FZD++Wcf8M+DkPQVTgK+XFjWSe6I dzkKPf6tEMKiIMnHu3nRX35QXLshgVU0NU1MzvHua1QhYf6D15Tj8zUK7MpZpyHl0SCs zsw07DghloAy/d1e1yumQDMQdrvnMnPMIsIR6DuwWvUzRe3qQyqcrtmButecDXmlj7mX rqvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=qYLGulgiXtqkGHB5690TZrqi9P52kY4/ILEk7GNvo8I=; b=I+WORPChGJXcI+FJgdBTHO5K0MrTXU5c/BHdI59zE0mR/6WlH3O1FIiNjQtKwaHmEE ga5fSvYR4oS2AiI8yMd6/7/8d3PTq3Q4SsSPwOW8VqAbbVMFGOsMpZnSjHMEYueM7rBp VwDFhkxtlIFpP/7k1donC3bmxoQmWSwGC7cphNDCL6K1rKsNc3nd7ONAyNZ/fnHnscog eZNeWvqbl2DVbGXkCmZ57Ag5bTlX1Agdv+BBcdnuqlqgq3mLQX9tVzHmPC7HrctaKc/m 5GKuHZFDG3ggKnMBqIaGYgIkb0nVYFora4WRDFcqEjIMUGmeM+KK96DRD3QaRfDMYqDd Qcqg== X-Gm-Message-State: AOAM5334L52GQcT/BdAHqQ3HgJ04dj5QFXnUjMeFrTD1qbvePGQXdQbE F6nt5/VREzhynKegWEBFZC0i3Q== X-Google-Smtp-Source: ABdhPJzERzhGKPBQiikc9HIAelrTIToUaE4SM6vylFfp/3XqAiKYqLEFKxNbx2dUn/bo6K2457Es0Q== X-Received: by 2002:a37:2f06:0:b0:6a0:5596:f395 with SMTP id v6-20020a372f06000000b006a05596f395mr16675021qkh.298.1652810585229; Tue, 17 May 2022 11:03:05 -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 o5-20020a05620a110500b006a0b40689b6sm7737036qkk.135.2022.05.17.11.03.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 May 2022 11:03:04 -0700 (PDT) Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1nr1XD-0087sl-Ll; Tue, 17 May 2022 15:03:03 -0300 Date: Tue, 17 May 2022 15:03:03 -0300 From: Jason Gunthorpe To: Christophe JAILLET Cc: Haowen Bai , Dennis Dalessandro , Leon Romanovsky , linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] RDMA: remove null check after call container_of() Message-ID: <20220517180303.GK63055@ziepe.ca> References: <1652751208-23211-1-git-send-email-baihaowen@meizu.com> <20220517121646.GE63055@ziepe.ca> <142a9c03-574f-adcf-bc4d-bb2a25c01e88@wanadoo.fr> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <142a9c03-574f-adcf-bc4d-bb2a25c01e88@wanadoo.fr> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, May 17, 2022 at 07:54:38PM +0200, Christophe JAILLET wrote: > Le 17/05/2022 à 14:16, Jason Gunthorpe a écrit : > > On Tue, May 17, 2022 at 09:33:28AM +0800, Haowen Bai wrote: > > > container_of() will never return NULL, so remove useless code. > > > > It is confusing here, but it can be null. > > Hi, > > out of curiosity, can you elaborate how it can be NULL? It is guarented/required that that container_of is a 0 offset. The normal usage of the ib_alloc_device macro: #define ib_alloc_device(drv_struct, member) \ container_of(_ib_alloc_device(sizeof(struct drv_struct) + \ BUILD_BUG_ON_ZERO(offsetof( \ struct drv_struct, member))), \ struct drv_struct, member) Enforces this property with a BUILD_BUG_ON So, if the input pointer to container_of is reliably NULL or ERR_PTR then the output pointer will be the same. The rvt code here open codes the call because it is a mid-layer and the sizeof() calculation above is not correct for it. Jason