]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
time/timecounter: Fix the lie that struct cyclecounter is const
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 1 Jul 2025 12:32:25 +0000 (14:32 +0200)
committerThomas Gleixner <tglx@linutronix.de>
Tue, 1 Jul 2025 13:38:25 +0000 (15:38 +0200)
In both the read callback for struct cyclecounter, and in struct
timecounter, struct cyclecounter is declared as a const pointer.

Unfortunatly, a number of users of this pointer treat it as a non-const
pointer as it is burried in a larger structure that is heavily modified by
the callback function when accessed.  This lie had been hidden by the fact
that container_of() "casts away" a const attribute of a pointer without any
compiler warning happening at all.

Fix this all up by removing the const attribute in the needed places so
that everyone can see that the structure really isn't const, but can,
and is, modified by the users of it.

Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/all/2025070124-backyard-hurt-783a@gregkh
28 files changed:
arch/microblaze/kernel/timer.c
drivers/clocksource/arm_arch_timer.c
drivers/net/can/rockchip/rockchip_canfd-timestamp.c
drivers/net/can/spi/mcp251xfd/mcp251xfd-timestamp.c
drivers/net/can/usb/gs_usb.c
drivers/net/dsa/mv88e6xxx/chip.h
drivers/net/dsa/mv88e6xxx/ptp.c
drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
drivers/net/ethernet/broadcom/bnxt/bnxt_ptp.c
drivers/net/ethernet/cavium/common/cavium_ptp.c
drivers/net/ethernet/freescale/fec_ptp.c
drivers/net/ethernet/intel/e1000e/netdev.c
drivers/net/ethernet/intel/igb/igb_ptp.c
drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
drivers/net/ethernet/marvell/octeontx2/nic/otx2_ptp.c
drivers/net/ethernet/mellanox/mlx4/en_clock.c
drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c
drivers/net/ethernet/mellanox/mlxsw/spectrum_ptp.c
drivers/net/ethernet/pensando/ionic/ionic_phc.c
drivers/net/ethernet/qlogic/qede/qede_ptp.c
drivers/net/ethernet/ti/cpts.c
drivers/net/ethernet/wangxun/libwx/wx_ptp.c
drivers/ptp/ptp_mock.c
drivers/ptp/ptp_vclock.c
include/linux/timecounter.h
kernel/time/timecounter.c
sound/hda/hdac_stream.c

index ccb4b4b59bca128a060e18e7ca1d3c4fa9448d2f..a2ab67b747a19aaac023ae44133f3f46be197448 100644 (file)
@@ -193,7 +193,7 @@ static struct timecounter xilinx_tc = {
        .cc = NULL,
 };
 
-static u64 xilinx_cc_read(const struct cyclecounter *cc)
+static u64 xilinx_cc_read(struct cyclecounter *cc)
 {
        return xilinx_read(NULL);
 }
index 981a578043a59d2a7c9d689eb60130eddf18ca97..80ba6a54248c4c4b645092787db1039fbc26b8d1 100644 (file)
@@ -243,7 +243,7 @@ static u64 arch_counter_read(struct clocksource *cs)
        return arch_timer_read_counter();
 }
 
-static u64 arch_counter_read_cc(const struct cyclecounter *cc)
+static u64 arch_counter_read_cc(struct cyclecounter *cc)
 {
        return arch_timer_read_counter();
 }
index fa85a75be65a6d52bd1d6b2fff79a8e13dc2a7ca..72774cd2f94b77cbfad48b6ff968aa910c3176b3 100644 (file)
@@ -8,7 +8,7 @@
 
 #include "rockchip_canfd.h"
 
-static u64 rkcanfd_timestamp_read(const struct cyclecounter *cc)
+static u64 rkcanfd_timestamp_read(struct cyclecounter *cc)
 {
        const struct rkcanfd_priv *priv = container_of(cc, struct rkcanfd_priv, cc);
 
index 202ca0d24d03b9f5bebba23a9f8d0e6f6422c728..413a5cb75c13249ed87b16b446f02cad5d265ec1 100644 (file)
@@ -11,7 +11,7 @@
 
 #include "mcp251xfd.h"
 
-static u64 mcp251xfd_timestamp_raw_read(const struct cyclecounter *cc)
+static u64 mcp251xfd_timestamp_raw_read(struct cyclecounter *cc)
 {
        const struct mcp251xfd_priv *priv;
        u32 ts_raw = 0;
index bb6335278e46f75ce13597aa08a5784d53912a77..c9482d6e947b0c7b033dc4f0c35f5b111e1bfd92 100644 (file)
@@ -420,7 +420,7 @@ static inline int gs_usb_get_timestamp(const struct gs_usb *parent,
        return 0;
 }
 
-static u64 gs_usb_timestamp_read(const struct cyclecounter *cc) __must_hold(&dev->tc_lock)
+static u64 gs_usb_timestamp_read(struct cyclecounter *cc) __must_hold(&dev->tc_lock)
 {
        struct gs_usb *parent = container_of(cc, struct gs_usb, cc);
        u32 timestamp = 0;
index 7d00482f53a3b69424d4171dd272b704e282adb7..feddf505c9186e3be085d8f9f2f5d7fd083f9e32 100644 (file)
@@ -732,7 +732,7 @@ struct mv88e6xxx_avb_ops {
 };
 
 struct mv88e6xxx_ptp_ops {
-       u64 (*clock_read)(const struct cyclecounter *cc);
+       u64 (*clock_read)(struct cyclecounter *cc);
        int (*ptp_enable)(struct ptp_clock_info *ptp,
                          struct ptp_clock_request *rq, int on);
        int (*ptp_verify)(struct ptp_clock_info *ptp, unsigned int pin,
index 1d3b2c94c53ee2b4b784fbea7244734cbb7eb4a0..e8c9207e932e64fe68c0c88b1d69ddfbe0cbc80b 100644 (file)
@@ -138,7 +138,7 @@ mv88e6xxx_cc_coeff_get(struct mv88e6xxx_chip *chip)
        }
 }
 
-static u64 mv88e6352_ptp_clock_read(const struct cyclecounter *cc)
+static u64 mv88e6352_ptp_clock_read(struct cyclecounter *cc)
 {
        struct mv88e6xxx_chip *chip = cc_to_chip(cc);
        u16 phc_time[2];
@@ -152,7 +152,7 @@ static u64 mv88e6352_ptp_clock_read(const struct cyclecounter *cc)
                return ((u32)phc_time[1] << 16) | phc_time[0];
 }
 
-static u64 mv88e6165_ptp_clock_read(const struct cyclecounter *cc)
+static u64 mv88e6165_ptp_clock_read(struct cyclecounter *cc)
 {
        struct mv88e6xxx_chip *chip = cc_to_chip(cc);
        u16 phc_time[2];
@@ -483,7 +483,7 @@ const struct mv88e6xxx_ptp_ops mv88e6390_ptp_ops = {
                (1 << HWTSTAMP_FILTER_PTP_V2_DELAY_REQ),
 };
 
-static u64 mv88e6xxx_ptp_clock_read(const struct cyclecounter *cc)
+static u64 mv88e6xxx_ptp_clock_read(struct cyclecounter *cc)
 {
        struct mv88e6xxx_chip *chip = cc_to_chip(cc);
 
index 978c4dd01fa0a505b40a8c5b4a195eb452f235e0..e8d5c05de77ad8c867c7daf451ee8820bc5f0418 100644 (file)
@@ -13,7 +13,7 @@
 #include "xgbe.h"
 #include "xgbe-common.h"
 
-static u64 xgbe_cc_read(const struct cyclecounter *cc)
+static u64 xgbe_cc_read(struct cyclecounter *cc)
 {
        struct xgbe_prv_data *pdata = container_of(cc,
                                                   struct xgbe_prv_data,
index c9a1a1d504c0f3ebad4197b42ea30f3db76864dc..48ad2d6e125bd1b31a68035b9b935353dd2ed77f 100644 (file)
@@ -15176,7 +15176,7 @@ void bnx2x_set_rx_ts(struct bnx2x *bp, struct sk_buff *skb)
 }
 
 /* Read the PHC */
-static u64 bnx2x_cyclecounter_read(const struct cyclecounter *cc)
+static u64 bnx2x_cyclecounter_read(struct cyclecounter *cc)
 {
        struct bnx2x *bp = container_of(cc, struct bnx2x, cyclecounter);
        int port = BP_PORT(bp);
index 0669d43472f51b11bbb7a7f6528f6c6b92f22f9a..7542b6d2568b9425bf8dc19be6645b4a6f3c52c0 100644 (file)
@@ -702,7 +702,7 @@ static void bnxt_unmap_ptp_regs(struct bnxt *bp)
                  (BNXT_PTP_GRC_WIN - 1) * 4);
 }
 
-static u64 bnxt_cc_read(const struct cyclecounter *cc)
+static u64 bnxt_cc_read(struct cyclecounter *cc)
 {
        struct bnxt_ptp_cfg *ptp = container_of(cc, struct bnxt_ptp_cfg, cc);
        u64 ns = 0;
index 984f0dd7b62e19e35cf789fe870b102e5ad8ca9d..61e2616570734a045169e36abf0bf60bb0abf76f 100644 (file)
@@ -209,7 +209,7 @@ static int cavium_ptp_enable(struct ptp_clock_info *ptp_info,
        return -EOPNOTSUPP;
 }
 
-static u64 cavium_ptp_cc_read(const struct cyclecounter *cc)
+static u64 cavium_ptp_cc_read(struct cyclecounter *cc)
 {
        struct cavium_ptp *clock =
                container_of(cc, struct cavium_ptp, cycle_counter);
index 876d908325964388e939efd7a7c7e694609817fa..c28ca17a81fd5f25f53d41f295fda48780f1c27f 100644 (file)
@@ -96,7 +96,7 @@
  * cyclecounter structure used to construct a ns counter from the
  * arbitrary fixed point registers
  */
-static u64 fec_ptp_read(const struct cyclecounter *cc)
+static u64 fec_ptp_read(struct cyclecounter *cc)
 {
        struct fec_enet_private *fep =
                container_of(cc, struct fec_enet_private, cc);
index 7719e15813eeac151190ba5b896d43ec145c956b..b27a61fab371724dca5b0a20d0e2da91da7f9ea4 100644 (file)
@@ -4436,7 +4436,7 @@ u64 e1000e_read_systim(struct e1000_adapter *adapter,
  * e1000e_cyclecounter_read - read raw cycle counter (used by time counter)
  * @cc: cyclecounter structure
  **/
-static u64 e1000e_cyclecounter_read(const struct cyclecounter *cc)
+static u64 e1000e_cyclecounter_read(struct cyclecounter *cc)
 {
        struct e1000_adapter *adapter = container_of(cc, struct e1000_adapter,
                                                     cc);
index 793c96016288089844f521a36da8908ba820e3db..2f1fae2bcdd2959f1c865af44f4223adb0825a76 100644 (file)
@@ -73,7 +73,7 @@ static void igb_ptp_tx_hwtstamp(struct igb_adapter *adapter);
 static void igb_ptp_sdp_init(struct igb_adapter *adapter);
 
 /* SYSTIM read access for the 82576 */
-static u64 igb_ptp_read_82576(const struct cyclecounter *cc)
+static u64 igb_ptp_read_82576(struct cyclecounter *cc)
 {
        struct igb_adapter *igb = container_of(cc, struct igb_adapter, cc);
        struct e1000_hw *hw = &igb->hw;
@@ -90,7 +90,7 @@ static u64 igb_ptp_read_82576(const struct cyclecounter *cc)
 }
 
 /* SYSTIM read access for the 82580 */
-static u64 igb_ptp_read_82580(const struct cyclecounter *cc)
+static u64 igb_ptp_read_82580(struct cyclecounter *cc)
 {
        struct igb_adapter *igb = container_of(cc, struct igb_adapter, cc);
        struct e1000_hw *hw = &igb->hw;
index eef25e11d9381adb4208a97204b91ecd99226026..eafb61415bd1076ad7de583b39c1977116175c45 100644 (file)
@@ -327,7 +327,7 @@ static void ixgbe_ptp_setup_sdp_X550(struct ixgbe_adapter *adapter)
  * result of SYSTIME is 32bits of "billions of cycles" and 32 bits of
  * "cycles", rather than seconds and nanoseconds.
  */
-static u64 ixgbe_ptp_read_X550(const struct cyclecounter *cc)
+static u64 ixgbe_ptp_read_X550(struct cyclecounter *cc)
 {
        struct ixgbe_adapter *adapter =
                container_of(cc, struct ixgbe_adapter, hw_cc);
@@ -364,7 +364,7 @@ static u64 ixgbe_ptp_read_X550(const struct cyclecounter *cc)
  * cyclecounter structure used to construct a ns counter from the
  * arbitrary fixed point registers
  */
-static u64 ixgbe_ptp_read_82599(const struct cyclecounter *cc)
+static u64 ixgbe_ptp_read_82599(struct cyclecounter *cc)
 {
        struct ixgbe_adapter *adapter =
                container_of(cc, struct ixgbe_adapter, hw_cc);
index 63130ba37e9df1feb01b02a25d357e7bb7e95f7e..e52cc6b1a26cc8aad601992ace21ec66e47a8cce 100644 (file)
@@ -193,7 +193,7 @@ static int ptp_pps_on(struct otx2_ptp *ptp, int on, u64 period)
        return otx2_sync_mbox_msg(&ptp->nic->mbox);
 }
 
-static u64 ptp_cc_read(const struct cyclecounter *cc)
+static u64 ptp_cc_read(struct cyclecounter *cc)
 {
        struct otx2_ptp *ptp = container_of(cc, struct otx2_ptp, cycle_counter);
 
index d73a2044dc2662f34365db74d2fd2338fd19a013..2aeaafcfb993a4e1d4d7681ec19db0924392924a 100644 (file)
@@ -38,7 +38,7 @@
 
 /* mlx4_en_read_clock - read raw cycle counter (to be used by time counter)
  */
-static u64 mlx4_en_read_clock(const struct cyclecounter *tc)
+static u64 mlx4_en_read_clock(struct cyclecounter *tc)
 {
        struct mlx4_en_dev *mdev =
                container_of(tc, struct mlx4_en_dev, cycles);
index cec18efadc7330c84ce545efc5922c359ac6b470..214d732d18e9012e1444571323ad81791aecf43a 100644 (file)
@@ -343,7 +343,7 @@ static u64 mlx5_read_time(struct mlx5_core_dev *dev,
                           (u64)timer_l | (u64)timer_h1 << 32;
 }
 
-static u64 read_internal_timer(const struct cyclecounter *cc)
+static u64 read_internal_timer(struct cyclecounter *cc)
 {
        struct mlx5_timer *timer = container_of(cc, struct mlx5_timer, cycles);
        struct mlx5_clock *clock = container_of(timer, struct mlx5_clock, timer);
index e8182dd76c7dc85b60838cef99197325fef60763..5b9f0844b8f60693868f432f7448863da40c925b 100644 (file)
@@ -131,7 +131,7 @@ static u64 __mlxsw_sp1_ptp_read_frc(struct mlxsw_sp1_ptp_clock *clock,
        return (u64) frc_l | (u64) frc_h2 << 32;
 }
 
-static u64 mlxsw_sp1_ptp_read_frc(const struct cyclecounter *cc)
+static u64 mlxsw_sp1_ptp_read_frc(struct cyclecounter *cc)
 {
        struct mlxsw_sp1_ptp_clock *clock =
                container_of(cc, struct mlxsw_sp1_ptp_clock, cycles);
index 7505efdff8e95c305f747c4c6e52a7e49ac9c4d5..9f5c81d44f995e45b6eea424e84683783bbe26ea 100644 (file)
@@ -290,7 +290,7 @@ static u64 ionic_hwstamp_read(struct ionic *ionic,
        return (u64)tick_low | ((u64)tick_high << 32);
 }
 
-static u64 ionic_cc_read(const struct cyclecounter *cc)
+static u64 ionic_cc_read(struct cyclecounter *cc)
 {
        struct ionic_phc *phc = container_of(cc, struct ionic_phc, cc);
        struct ionic *ionic = phc->lif->ionic;
index 9d6399a5c780d1a0ef6958738034835844ed6791..a38f1e72c62bf7d971ae67ff82cafc6d973d8120 100644 (file)
@@ -181,7 +181,7 @@ static void qede_ptp_task(struct work_struct *work)
 }
 
 /* Read the PHC. This API is invoked with ptp_lock held. */
-static u64 qede_ptp_read_cc(const struct cyclecounter *cc)
+static u64 qede_ptp_read_cc(struct cyclecounter *cc)
 {
        struct qede_dev *edev;
        struct qede_ptp *ptp;
index dbbea914604057ca97823c5c6e164be50303df08..2ba4c8795d605e41178063ff9fb3b327c5a631aa 100644 (file)
@@ -181,7 +181,7 @@ void cpts_misc_interrupt(struct cpts *cpts)
 }
 EXPORT_SYMBOL_GPL(cpts_misc_interrupt);
 
-static u64 cpts_systim_read(const struct cyclecounter *cc)
+static u64 cpts_systim_read(struct cyclecounter *cc)
 {
        struct cpts *cpts = container_of(cc, struct cpts, cc);
 
index 2c39b879f977e58933e400cafded47aaa7299f81..44f3e65052468fd272a02cef076223f73fecf532 100644 (file)
@@ -652,7 +652,7 @@ static int wx_ptp_set_timestamp_mode(struct wx *wx,
        return 0;
 }
 
-static u64 wx_ptp_read(const struct cyclecounter *hw_cc)
+static u64 wx_ptp_read(struct cyclecounter *hw_cc)
 {
        struct wx *wx = container_of(hw_cc, struct wx, hw_cc);
 
index e7b459c846a2c9695004018b644c5e4047d3fae4..bbd14ce24b34db09273a4f27d4253c6f5c51da5c 100644 (file)
@@ -41,7 +41,7 @@ struct mock_phc {
        spinlock_t lock;
 };
 
-static u64 mock_phc_cc_read(const struct cyclecounter *cc)
+static u64 mock_phc_cc_read(struct cyclecounter *cc)
 {
        return ktime_get_raw_ns();
 }
index 7febfdcbde8bc6cdc70c6d7a3567bede87c66114..2fdeedd60e21b3d3a3afb99201179b58c34a10b0 100644 (file)
@@ -164,7 +164,7 @@ static const struct ptp_clock_info ptp_vclock_info = {
        .do_aux_work    = ptp_vclock_refresh,
 };
 
-static u64 ptp_vclock_read(const struct cyclecounter *cc)
+static u64 ptp_vclock_read(struct cyclecounter *cc)
 {
        struct ptp_vclock *vclock = cc_to_vclock(cc);
        struct ptp_clock *ptp = vclock->pclock;
index 0982d1d52b24d9cbb5da81ad2adaa9f4340e66e5..dce03a5cafb7cfe61bd83304ef49f7721735da64 100644 (file)
@@ -28,7 +28,7 @@
  * @shift:             cycle to nanosecond divisor (power of two)
  */
 struct cyclecounter {
-       u64 (*read)(const struct cyclecounter *cc);
+       u64 (*read)(struct cyclecounter *cc);
        u64 mask;
        u32 mult;
        u32 shift;
@@ -53,7 +53,7 @@ struct cyclecounter {
  * @frac:              accumulated fractional nanoseconds
  */
 struct timecounter {
-       const struct cyclecounter *cc;
+       struct cyclecounter *cc;
        u64 cycle_last;
        u64 nsec;
        u64 mask;
@@ -100,7 +100,7 @@ static inline void timecounter_adjtime(struct timecounter *tc, s64 delta)
  * the time stamp counter by the number of elapsed nanoseconds.
  */
 extern void timecounter_init(struct timecounter *tc,
-                            const struct cyclecounter *cc,
+                            struct cyclecounter *cc,
                             u64 start_tstamp);
 
 /**
index e6285288d76572d192435a1a44babc57bfda8770..3d2a354cfe1c1b205aa960a748a76f8dd94335e2 100644 (file)
@@ -6,7 +6,7 @@
 #include <linux/timecounter.h>
 
 void timecounter_init(struct timecounter *tc,
-                     const struct cyclecounter *cc,
+                     struct cyclecounter *cc,
                      u64 start_tstamp)
 {
        tc->cc = cc;
index e7f6208af5b06e715f3cc1c8cb2434502ce87cb6..4a87bef8834f9c31a2eef5c926cd66ea1b8cf628 100644 (file)
@@ -634,7 +634,7 @@ int snd_hdac_stream_set_params(struct hdac_stream *azx_dev,
 }
 EXPORT_SYMBOL_GPL(snd_hdac_stream_set_params);
 
-static u64 azx_cc_read(const struct cyclecounter *cc)
+static u64 azx_cc_read(struct cyclecounter *cc)
 {
        struct hdac_stream *azx_dev = container_of(cc, struct hdac_stream, cc);