• Kees Cook's avatar
    overflow: Add struct_size_t() helper · d67790dd
    Kees Cook authored
    While struct_size() is normally used in situations where the structure
    type already has a pointer instance, there are places where no variable
    is available. In the past, this has been worked around by using a typed
    NULL first argument, but this is a bit ugly. Add a helper to do this,
    and replace the handful of instances of the code pattern with it.
    
    Instances were found with this Coccinelle script:
    
    @struct_size_t@
    identifier STRUCT, MEMBER;
    expression COUNT;
    @@
    
    -       struct_size((struct STRUCT *)\(0\|NULL\),
    +       struct_size_t(struct STRUCT,
                    MEMBER, COUNT)
    Suggested-by: default avatarChristoph Hellwig <hch@infradead.org>
    Cc: Jesse Brandeburg <jesse.brandeburg@intel.com>
    Cc: Tony Nguyen <anthony.l.nguyen@intel.com>
    Cc: "David S. Miller" <davem@davemloft.net>
    Cc: Eric Dumazet <edumazet@google.com>
    Cc: Paolo Abeni <pabeni@redhat.com>
    Cc: James Smart <james.smart@broadcom.com>
    Cc: Keith Busch <kbusch@kernel.org>
    Cc: Jens Axboe <axboe@kernel.dk>
    Cc: Sagi Grimberg <sagi@grimberg.me>
    Cc: HighPoint Linux Team <linux@highpoint-tech.com>
    Cc: "James E.J. Bottomley" <jejb@linux.ibm.com>
    Cc: "Martin K. Petersen" <martin.petersen@oracle.com>
    Cc: Kashyap Desai <kashyap.desai@broadcom.com>
    Cc: Sumit Saxena <sumit.saxena@broadcom.com>
    Cc: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
    Cc: Don Brace <don.brace@microchip.com>
    Cc: "Darrick J. Wong" <djwong@kernel.org>
    Cc: Dave Chinner <dchinner@redhat.com>
    Cc: Guo Xuenan <guoxuenan@huawei.com>
    Cc: Gwan-gyeong Mun <gwan-gyeong.mun@intel.com>
    Cc: Nick Desaulniers <ndesaulniers@google.com>
    Cc: Daniel Latypov <dlatypov@google.com>
    Cc: kernel test robot <lkp@intel.com>
    Cc: intel-wired-lan@lists.osuosl.org
    Cc: netdev@vger.kernel.org
    Cc: linux-nvme@lists.infradead.org
    Cc: linux-scsi@vger.kernel.org
    Cc: megaraidlinux.pdl@broadcom.com
    Cc: storagedev@microchip.com
    Cc: linux-xfs@vger.kernel.org
    Cc: linux-hardening@vger.kernel.org
    Signed-off-by: default avatarKees Cook <keescook@chromium.org>
    Acked-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
    Reviewed-by: default avatarDarrick J. Wong <djwong@kernel.org>
    Reviewed-by: default avatarGustavo A. R. Silva <gustavoars@kernel.org>
    Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
    Acked-by: default avatarJakub Kicinski <kuba@kernel.org>
    Reviewed-by: default avatarAlexander Lobakin <aleksander.lobakin@intel.com>
    Link: https://lore.kernel.org/r/20230522211810.never.421-kees@kernel.org
    d67790dd
megaraid_sas_base.c 248 KB