Skip to contentSkip to conversation

drbd: rcu_read_lock() and rcu_dereference() for tconn->net_conf

Drbd-dev Philipp Reisner 1 participant 1 message Nov 16, 2012 1 message not in the archive DRBD driver

lore
Share & tools
lore

Philipp Reisner

author maintainer
#1 lore raw
In reply to a message not in the archive

Am Montag, 12. November 2012, 22:06:59 schrieb Dan Carpenter:

Quoted 19 lines

Hello Philipp Reisner,

This is a semi-automatic email about new static checker warnings.

The patch 44ed167da748: "drbd: rcu_read_lock() and rcu_dereference() for tconn->net_conf" from Apr 19, 2011, leads to the following Smatch complaint:

drivers/block/drbd/drbd_state.c:566 is_valid_state()
error: we previously assumed 'nc' could be null (see line 525)

drivers/block/drbd/drbd_state.c

   524		nc = rcu_dereference(mdev->tconn->net_conf);
   525		if (nc) {
                    ^^

New check.

   526			if (!nc->two_primaries && ns.role == R_PRIMARY) {
   527				if (ns.peer == R_PRIMARY)

[...]

Quoted 7 lines
   565		else if ((ns.conn == C_VERIFY_S || ns.conn == C_VERIFY_T) &&
   566			 (nc->verify_alg[0] == 0))
                          ^^^^^^^^^^^^^^

New dereference.
Probably a false positive, but it's not immediately obvious what's going on. Maybe add a comment?

For developers familiar with the DRBD code it is obvious that if an online verify may start (ns.conn == C_VERIFY_S || ns.conn == C_VERIFY_T) we have an established connection, and that implies that nc is not NULL.

So, yes, it is a false positive.

Best,
Phil