soc: fsl: cpm1: qmc: Fix assigned timeslot masks
authorHerve Codina via Alsa-devel <alsa-devel@alsa-project.org>
Tue, 7 Mar 2023 14:15:03 +0000 (15:15 +0100)
committerMark Brown <broonie@kernel.org>
Wed, 8 Mar 2023 17:04:53 +0000 (17:04 +0000)
The assigned timeslot masks are 64bit values.
In case of 64 timeslots the code uses (1 << 64) which is undefined on a
64bit value. On the PowerPC architecture, this lead to an incorrect
result as (1 << 64) produces the same result as (1 << 0).

Fix the masks values taking care of the 64 timeslots case.

Signed-off-by: Herve Codina <herve.codina@bootlin.com>
Link: https://lore.kernel.org/r/167819855177.26.11163930602844526001@mailman-core.alsa-project.org
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/soc/fsl/qe/qmc.c

index cfa7207353e0a7f8625411bb4b22f19e054dc2bf..b3c292c9a14eae0990e5040236f1d3999e0001d1 100644 (file)
@@ -754,6 +754,11 @@ static int qmc_check_chans(struct qmc *qmc)
        if (ret)
                return ret;
 
+       if ((info.nb_tx_ts > 64) || (info.nb_rx_ts > 64)) {
+               dev_err(qmc->dev, "Number of TSA Tx/Rx TS assigned not supported\n");
+               return -EINVAL;
+       }
+
        /*
         * If more than 32 TS are assigned to this serial, one common table is
         * used for Tx and Rx and so masks must be equal for all channels.
@@ -766,9 +771,8 @@ static int qmc_check_chans(struct qmc *qmc)
                is_one_table = true;
        }
 
-
-       tx_ts_assigned_mask = (((u64)1) << info.nb_tx_ts) - 1;
-       rx_ts_assigned_mask = (((u64)1) << info.nb_rx_ts) - 1;
+       tx_ts_assigned_mask = info.nb_tx_ts == 64 ? U64_MAX : (((u64)1) << info.nb_tx_ts) - 1;
+       rx_ts_assigned_mask = info.nb_rx_ts == 64 ? U64_MAX : (((u64)1) << info.nb_rx_ts) - 1;
 
        list_for_each_entry(chan, &qmc->chan_head, list) {
                if (chan->tx_ts_mask > tx_ts_assigned_mask) {