Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp262095pxb; Thu, 25 Feb 2021 01:37:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJziNIgjruyjilUt7KxH4zdDw0saZ6akh36K3kR2w8b+wEhS7XYaeymdE9JGQFj5txEFdtcc X-Received: by 2002:a05:6402:2553:: with SMTP id l19mr1939670edb.326.1614245821961; Thu, 25 Feb 2021 01:37:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614245821; cv=none; d=google.com; s=arc-20160816; b=AMiyVVkldw32jr2+G0tbNZ01S/6/NAbx525n78qnPHWSVEkESIwl9PuYdd3z5tzLt+ +y84qCfueuAm5OSZdS/AhYQ5yJxJFCunmPVC9ja+f7PSIIa40RlLdGNG08Rl/URpAsQj hIqcmthmq+Jtr4tVv84WLsSRqYb3qmD7kKeU4oj6/TQ7UgfrlG16fbqecNgHqLoguBCB MmzgTbjOZXbMd4hmOzqU0ePc4CgIA3ySc3jQakfRSg+5Oo2dG53eITIzlfyCHHVeMLTY LtfSbr6Zk3pxm58SSJhi4A8108tD7fP/crj1LxEiy//FydZQtj4uvTNcGtpSY0W1fQbC 1q9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version; bh=3l1PKqMmtHsqelzh4HyKblC2FIVDbPFrPkrWcmQSfDE=; b=eRJ1unXMMh/lFkXlfZt8izdKSNyCEucZEck4rSRr8uvvZXxsF5kDSZdP8SSkdjKyd/ 8RfMx02TCm/DaoqQZbrF4+HA1h70zmS3k8FNEHF9SB/4Efw4NyhHleSmMKbU1RamgMkN Y83r9HlYR82EESZpXi8RQ16ALlc0NjUHc1etGBMkhiJf2d2LNqlbHz+VaeByIom11tpc Ubt+86wOyk+q6CZynxTIF2VzAvQZIsN4VCPn9XWJBSrQdmmL1apW7A5cYJg/K/18tP8s g2YQgy8LoNeqBH6Dif5Apd+IrnEyS1mACYCrcxvnUokAaJFGLGBsB76NbABQCmALAWWf II0w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i20si2931849edg.156.2021.02.25.01.36.39; Thu, 25 Feb 2021 01:37:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234022AbhBYH3O (ORCPT + 99 others); Thu, 25 Feb 2021 02:29:14 -0500 Received: from mail-oi1-f179.google.com ([209.85.167.179]:46404 "EHLO mail-oi1-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233780AbhBYH3I (ORCPT ); Thu, 25 Feb 2021 02:29:08 -0500 Received: by mail-oi1-f179.google.com with SMTP id f3so5171358oiw.13; Wed, 24 Feb 2021 23:28:52 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=3l1PKqMmtHsqelzh4HyKblC2FIVDbPFrPkrWcmQSfDE=; b=p6WCtXuObl4PWW6GxFG7eze62pAo+3KdGMr2vEzFcxVtyY8wTiADRi1YP+mHY/D8Zg e18w52BbppBRAgT+UVdoetTdqD2cCvEAUskTmaI6xFtDuDvEVgRuCKXO9wFQCaSeyQTW XTSqfDSa8X40QU0RIpd5P+0wEQgns9b8UGuWuRFpQ34LN3h8VOc4wOosrW0e7aXFSDZw PcCRtjGsc2eKVbxfo56BvQSszKLrTBn+6T/INNSIVx6R3eraoYGuDCH43JevnkMZAEws KOKcPn2xudrjkgDPH//EuES8X97ic6UpcJWvqTG8pamhjuHDHFcXkqbc6afyU+JLU6VB LD0Q== X-Gm-Message-State: AOAM530K+Uuewz2gTj2XHIrmKu8WgpcdBQ4EOIS6VeUiOamKB6T5qWkn 0CuPQKAXGpLR/psZxMjUIhkXTC1KTHpF/aeUydyv/jeHG+Q= X-Received: by 2002:aca:d8c6:: with SMTP id p189mr1118446oig.54.1614238107520; Wed, 24 Feb 2021 23:28:27 -0800 (PST) MIME-Version: 1.0 References: <20210223112003.2223332-1-geert+renesas@glider.be> <20210224224358.pysql5pu23zt7mtb@skbuf> In-Reply-To: <20210224224358.pysql5pu23zt7mtb@skbuf> From: Geert Uytterhoeven Date: Thu, 25 Feb 2021 08:28:15 +0100 Message-ID: Subject: Re: [PATCH] net: dsa: sja1105: Remove unneeded cast in sja1105_crc32() To: Vladimir Oltean Cc: Andrew Lunn , Vivien Didelot , Florian Fainelli , "David S . Miller" , Jakub Kicinski , netdev , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Vladimir, On Wed, Feb 24, 2021 at 11:44 PM Vladimir Oltean wrote: > On Tue, Feb 23, 2021 at 12:20:03PM +0100, Geert Uytterhoeven wrote: > > sja1105_unpack() takes a "const void *buf" as its first parameter, so > > there is no need to cast away the "const" of the "buf" variable before > > calling it. > > > > Drop the cast, as it prevents the compiler performing some checks. > > > > Signed-off-by: Geert Uytterhoeven > > --- > > Reviewed-by: Vladimir Oltean Thanks! > By the way, your email went straight to my spam box, I just found the > patch by mistake on patchwork. > > Why is this message in spam? > It is in violation of Google's recommended email sender guidelines. Yeah, sometimes Gmail can be annoying. I recommend adding a filter to never send emails with "PATCH" in the subject to spam. > > Compile-tested only. > > > > BTW, sja1105_packing() and packing() are really bad APIs, as the input > > pointer parameters cannot be const due to the direction depending on > > "op". This means the compiler cannot do const checks. Worse, callers > > are required to cast away constness to prevent the compiler from > > issueing warnings. Please don't do this! > > --- > > What const checks can the compiler not do? If you have a const and a non-const buffer, and accidentally call packing() with the two buffer pointers exchanged (this is a common mistake), you won't get a compiler warning. So having separate pack() and unpack() functions would be safer. You can rename packing() to __packing() to make it clear this function is not to be called directly without deep consideration, and have pack() and unpack() as wrappers just calling __packing(). Of course that means callers that do need a separate "op" parameter still need to call __packing(), but they can provide their own safer wrappers, too. > Also, if you know of an existing kernel API which can replace packing(), > I'm all ears. No idea. Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds