i2c: sprd: Fix the i2c count issue
[linux-block.git] / drivers / i2c / i2c-core-base.c
index 16a3b73375a637bd5a77267f9ca71913b69ef000..1ba40bb2b966a943eb2544c8b5710f1964b22aba 100644 (file)
@@ -69,18 +69,18 @@ static DEFINE_IDR(i2c_adapter_idr);
 
 static int i2c_detect(struct i2c_adapter *adapter, struct i2c_driver *driver);
 
-static struct static_key i2c_trace_msg = STATIC_KEY_INIT_FALSE;
+static DEFINE_STATIC_KEY_FALSE(i2c_trace_msg_key);
 static bool is_registered;
 
 int i2c_transfer_trace_reg(void)
 {
-       static_key_slow_inc(&i2c_trace_msg);
+       static_branch_inc(&i2c_trace_msg_key);
        return 0;
 }
 
 void i2c_transfer_trace_unreg(void)
 {
-       static_key_slow_dec(&i2c_trace_msg);
+       static_branch_dec(&i2c_trace_msg_key);
 }
 
 const struct i2c_device_id *i2c_match_id(const struct i2c_device_id *id,
@@ -517,7 +517,7 @@ static unsigned short i2c_encode_flags_to_addr(struct i2c_client *client)
 
 /* This is a permissive address validity check, I2C address map constraints
  * are purposely not enforced, except for the general call address. */
-int i2c_check_addr_validity(unsigned addr, unsigned short flags)
+static int i2c_check_addr_validity(unsigned int addr, unsigned short flags)
 {
        if (flags & I2C_CLIENT_TEN) {
                /* 10-bit address, all values are valid */
@@ -1845,14 +1845,18 @@ int __i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
        unsigned long orig_jiffies;
        int ret, try;
 
+       if (WARN_ON(!msgs || num < 1))
+               return -EINVAL;
+
        if (adap->quirks && i2c_check_for_quirks(adap, msgs, num))
                return -EOPNOTSUPP;
 
-       /* i2c_trace_msg gets enabled when tracepoint i2c_transfer gets
+       /*
+        * i2c_trace_msg_key gets enabled when tracepoint i2c_transfer gets
         * enabled.  This is an efficient way of keeping the for-loop from
         * being executed when not needed.
         */
-       if (static_key_false(&i2c_trace_msg)) {
+       if (static_branch_unlikely(&i2c_trace_msg_key)) {
                int i;
                for (i = 0; i < num; i++)
                        if (msgs[i].flags & I2C_M_RD)
@@ -1871,12 +1875,12 @@ int __i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
                        break;
        }
 
-       if (static_key_false(&i2c_trace_msg)) {
+       if (static_branch_unlikely(&i2c_trace_msg_key)) {
                int i;
                for (i = 0; i < ret; i++)
                        if (msgs[i].flags & I2C_M_RD)
                                trace_i2c_reply(adap, &msgs[i], i);
-               trace_i2c_result(adap, i, ret);
+               trace_i2c_result(adap, num, ret);
        }
 
        return ret;