You consider a cylinder with a piston inside which can move without friction, and with diathermic walls. The piston divides the cylinder into two rooms: A-B, filled with two ideal gases. There is also a valve that connects B and the outside. Let's consider just the room A as our thermodynimic system.
In the figure above are drawn two consecutive equilibria states of a generic reversible process, each described with a vector of thermodynamics variables. We assume that during the disequilibrium state, the piston moves of $dx$. You can observe that the only way to make the piston move is to use the valve; if the valve stays closed you can only have an isochoric process.
However, now we are intrested in calculating the work that our system (room A) has exchanged during the transition 1->2. In the equilibria states the net force acting on the piston is $0N$ because the pressure in the two rooms is the same, so the piston is firm. Using the kinetic energy theorem between the two equilibra states you obtain: $$dk=dW=0 $$ While I now that the right expression should be: $$dW=p dv$$ But I don't understand where it comes from, since it is in contrast with my treatment. And also, which pressure should I consider in this formula? Someone could show me exactly which point of my treatment is wrong?