You want to use a stored procedure but are using a function. There's a difference, you know?
Also I think you don't need a procedure at all, let alone a cursor. Cursors are expensive as hell.
Does this get you what you want?
SELECT * FROM (
SELECT
id,
qty,
@running_total:=@running_total + qty as running_total
FROM stock
, (SELECT @running_total:=0) vars
WHERE block_id=_block_id && type=2 && product_id=_product_id
ORDER BY time DESC, id DESC
) sq
WHERE running_total <= $yourRunningTotalLimit